Input_point: which component?
-
I'm writing a new tool, and I want to modify the component that the user has chosen. I can get the vertex from an input point, but how can I figure out which component that vertex is part of? CB.
-
Climb the tree. It has a parent, and it has also has a parent, and so on and so on.
-
Thanks Todd. That's what I've been trying to do. The input point will tell me the depth, but no matter how deep, I always seem to be in a shallow tree, which is component_definition, followed by a definition_list, followed by the model.
print("\n input point depth;" + @ip1.depth.to_s + "\n") print("vertex; " + vtx.position.to_s + "\n") p = vtx until p == Sketchup.active_model p = p.parent print("parent; " + p.to_s + "\n") end
Yields:
@unknownuser said:
input point depth:2
vertex: (0", 14.396265", 8")
parent: #Sketchup::ComponentDefinition:0xafca550
parent: #Sketchup::DefinitionList:0xafd7540
parent: #Sketchup::Model:0x4ddaa70input point depth:4
vertex: (0", 0", 2.75")
parent: #Sketchup::ComponentDefinition:0xafb90d8
parent: #Sketchup::DefinitionList:0xafd7540
parent: #Sketchup::Model:0x4ddaa70 -
Hey Clark.
OK, you mean which component instance. If so, that's a big hole in the OO model we have. I seem to remember trying to do this some time ago, and I don't remember if I figured it out or not. I know this has been discussed before. Sorry I don't have an immediate answer.
-
Well, even igonoring the instances, shouldn't one definition be nested within the next? These objects I'm clicking on are deeply nested sub-components. CB
-
When you do a pick, you can get get a picklist (name?) of all the entities that could have satisfied the pick, but maybe were deeper in the array of choices. So, perhaps the closest (read, "most outer") entity is being returned for the simple pick. Look deeper in the picklist (or whatever it's called) and perhaps pick the deepest entity - maybe that's the one you want.
-
Clark,
You can take inspiration from the following code
def which_component_picked(view, x, y, ip=nil) #Finding an edge or a face picked ip = Sketchup;;InputPoint.new unless ip ip.pick view, x, y ee = [ip.edge, ip.face].find { |e| e } return nil unless ee && ee.parent.class == Sketchup;;ComponentDefinition #Finding the instances in the pick list instances = ee.parent.instances ph = view.pick_helper ph.do_pick x, y comp = (ph.count > 0) ? ph.path_at(0).find { |e| instances.include?(e) } ; nil end
First you check if you have picked a vertex, an edge or a face. If so, you check if the parent is a ComponentDefinition.
Then you use a HelpPicker to check the full path of picked entities, and retrieve the first instance of the definition within this path.Fredo
-
This is exactly the info I needed. Thanks guys! CB.
Advertisement