Hightlight/select component with mouse over
-
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 -
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.
-
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.
-
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.
-
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?
-
@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
-
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.
Advertisement