sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Hightlight/select component with mouse over

    Scheduled Pinned Locked Moved Developers' Forum
    7 Posts 2 Posters 823 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F Offline
      Frankn
      last edited by

      I'm working on a custom tool and I just about have everything I want working, I'm working/modifying the linetool.rb file. One thing I'd like to add as a function is having the mouse select/highlight the bounding box just like the 'move' tool does and then get bounding box coords for the selected/highlighted component.

      As a second part, I'd like to limit drawing a line in the x,y planes, again something like hittong 'shift. when using the 'tape measure' tool but without having to use shift.

      Thanks,
      Frank

      1 Reply Last reply Reply Quote 0
      • F Offline
        Frankn
        last edited by

        Ok so I found how to get the name while hovering over a component... might not be the best way but it works... πŸ˜„

        
        select_comp=view.pick_helper
        select_comp.do_pick x,y
        selected_comp=select_comp.best_picked	    
         	    
        if selected_comp and selected_comp.is_a?(Sketchup;;ComponentInstance)
        selected_comp_name=selected_comp.definition.name
        Sketchup.active_model.selection.add selected_comp
        else
        Sketchup.active_model.selection.clear
        end  
        
        

        Still need to figure out how to get the bounding box to appear and retrieve it's coordinates. And also how to limit drawing a line only in the X and Y axis. πŸ˜•

        EDIT: Updated code to add selecting the component/bounding box.

        1 Reply Last reply Reply Quote 0
        • F Offline
          Frankn
          last edited by

          Here's another update...

          After selecting the component on a mouse over/hover I wanted to retrieve a few bits of information, component name, dimensions and which corner of the bounding box the cursor is pointing at. As per my previous update I was able to get the name and now I figured out how the get the dimensions... here's the code snippet.

          
          component_definition=selected_comp.definition
          component_height=bounds.depth
          component_depth=bounds.width
          component_width=bounds.height
          component_dimensions=[component_height, component_width, component_depth]
          
          

          I then send the info to the VCB.

          Now I need to figure out the bounding box corners and component orientation... wish me luck! πŸ˜• πŸ˜„ If anyone have ideas please share them... πŸ˜„

          p.s. hope the mods don't mind me updating my own post/question but I figure maybe the information will come in handy for another newb trying to do something similiar. I know for you advanced ruby guys/gals this is trvial but for a newb like me finding and then understanding how to implement this stuff is not easy.

          Let me know if you'd rather I stop.

          1 Reply Last reply Reply Quote 0
          • sdmitchS Offline
            sdmitch
            last edited by

            In your last code snippit, I think should be

            component_definition=selected_comp.definition
            component_height=selected_comp.bounds.depth# bounds.depth=z
            component_depth=selected_comp.bounds.height# bounds.height=y
            component_width=selected_comp.bounds.width# bounds.width=x
            component_dimensions=[component_width, component_depth, component_height]
            
            

            The individual corners and be accessed by selected_comp.bounds.corner(i) where i = 0 to 7
            0=front left bottom,1=front right bottom, 2=back left bottom, 3=back right bottom
            4=front left top, 5=front right top, 6=back left top, 7=back right top.

            To display the bounding box, you will need to use the Draw function in a tool I think.

            Nothing is worthless, it can always be used as a bad example.

            http://sdmitch.blogspot.com/

            1 Reply Last reply Reply Quote 0
            • F Offline
              Frankn
              last edited by

              Thanks sdmitch,

              I kinda figured that part out but what I can't figure out is how can I have the mouse input point (@ip1) find the individual corners?

              @ip1.position returns the screen coords but I can get it to return the bounding box coords. If the cursor was over the left, back, bottom corner (corner(2)) I want it to return corner(2) and not where corner 2 is located. Does that make any sense?

              1 Reply Last reply Reply Quote 0
              • sdmitchS Offline
                sdmitch
                last edited by

                @unknownuser said:

                I want it to return corner(2) and not where corner 2 is located.

                def onMouseMove(flags, x, y, view)
                 @ip.pick view,x,y;
                 ph = view.pick_helper; ph.do_pick x,y; best=ph.best_picked
                 if @ip.vertex && best.class==Sketchup;;ComponentInstance
                  phsh={}
                  for i in 0..7
                   dist=best.bounds.corner(i).distance(@ip.position)
                   phsh["corner #{i}"]=dist
                  end
                  corner=phsh.sort{|a,b| a[1]<=>b[1]}.map {|c| c[0]}
                  view.tooltip=corner[0]
                 else
                  view.tooltip = @ip.tooltip
                 end
                 view.refresh
                end
                
                

                Nothing is worthless, it can always be used as a bad example.

                http://sdmitch.blogspot.com/

                1 Reply Last reply Reply Quote 0
                • F Offline
                  Frankn
                  last edited by

                  WOW! Thanks sdmitch!!

                  That's way over my pay grade, Damn!

                  I tested it and it works great, though I must admit I'll have to study the code a lot to figure out how you did it and even then I'm not sure I'll get it. πŸ˜„

                  1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  • First post
                    Last post
                  Buy SketchPlus
                  Buy SUbD
                  Buy WrapR
                  Buy eBook
                  Buy Modelur
                  Buy Vertex Tools
                  Buy SketchCuisine
                  Buy FormFonts

                  Advertisement