Use PickHelper to find nested Instances?
-
How do I use a PickHelper to find a ComponentInstance which is nested several levels deep inside other Instances?
-
PickHelper.path_at
You'd have to find the index for the instance though. -
Thanks Thom. I guess I really don't understand what the PickHelper methods are supposed to do.
I had first tried
.all_picked
thinking it would return an Array of all elements in the pick (like the docs state.) What I am actually seeing is an array of all the exact same Instance (the top-level one.) Can that be correct -
You know what - I'm a wee bit confused myself right now when I try it out.
If you click on loose geometry, at a vertex corner you get edges and faces attached to the vertex.
But there is something odd with components and groups...hmm...
or maybe.... If you click on an edge inside a group, do you then get an array of three? if you iterate 1 - 2 as index and use path_at or leaf_at - do you then get different results? -
The
leaf_at
returns the 'deepest picked entity' - i.e. a face
You could then get its container / parent.
You could also have found that face frompicked_face
?
Thepickhelper
returns a list of 'picked objects' and its methods then let you sort through them ? -
Here's the scenario.
There is a "Joint" component made of only edges. Using a Tool, I need to be able to get the "global" position of its origin.
I know how to handle the nested trasnformations, but I thought the PickHelper would give me a list of the nested instances in order, which I can then use for the calculation.
-
This is where I think
.all_picked
is bugged out - it returns an array of the same Instance; where I think it ought to return an array of the nested instances.I think
.all_picked
is returning the correct number of things - it appears to send a ray through the point and picks up the entities both heading into the nest and also picks them up in reverse order as it's exiting the nest. -
array = pickhelper.path_at(pickhelper.count)
-
@jim said:
This is where I think
.all_picked
is bugged out - it returns an array of the same Instance; where I think it ought to return an array of the nested instances.I think
.all_picked
is returning the correct number of things - it appears to send a ray through the point and picks up the entities both heading into the nest and also picks them up in reverse order as it's exiting the nest..all_picked
return an array of entities containing the top level entity. You must use.leaf_at
to get the deepest item.When you use
.all_picked
after picking a point it'll return all top level entities within the given aperture. If you click on an edge attached to two faces it'll return an array containing the face and edges.If the faces and edges are contained within a group/component - then you get an array of the top level entity, which would be the group/component. You then need to use the count of the picked number of entities and traverse the tree of entities picked.
ph = view.pick_helper ph.init(x, y, 5) # (!) Allow user to customize pick aperture puts "Pick;" ph.do_pick x,y p ph.all_picked puts "> Paths;" for i in 1..ph.count p ph.path_at(i) end
Console output from this code after clicking a corner of a cube inside a group:
` Pick:
[#Sketchup::ComponentInstance:0x118a8a18, #Sketchup::ComponentInstance:0x118a8a18, #Sketchup::ComponentInstance:0x118a8a18, #Sketchup::ComponentInstance:0x118a8a18, #Sketchup::ComponentInstance:0x118a8a18, #Sketchup::ComponentInstance:0x118a8a18]Paths:
[#Sketchup::ComponentInstance:0x118a8a18, #Sketchup::Edge:0x117a98b0]
[#Sketchup::ComponentInstance:0x118a8a18, #Sketchup::Face:0x117a9838]
[#Sketchup::ComponentInstance:0x118a8a18, #Sketchup::Edge:0x117a97c0]
[#Sketchup::ComponentInstance:0x118a8a18, #Sketchup::Face:0x117a9748]
[#Sketchup::ComponentInstance:0x118a8a18, #Sketchup::Face:0x117a96d0]` -
Ok, so I need to go through each path until I find the Instance I am looking for?
If I do that in x-ray mode, it works. But it fails when I turn x-ray off.
-
@jim said:
Ok, so I need to go through each path until I find the Instance I am looking for?
I believe so. Unless there is a shortcut here that I've missed.
something like
for i in 0...(ph.count) if ph.path_at(i).include?(instance) path = ph.path_at(i) break end end
@jim said:
If I do that in x-ray mode, it works. But it fails when I turn x-ray off.
The output is different?
The sample output I posted in previous post was with X-Ray off... Not tried with it on.(Update with correct indexed.)
-
The docs are outright wrong about the index for the
*_at
methods. The index does not start at 1 - it start at 0. -
@jim said:
If I do that in x-ray mode, it works. But it fails when I turn x-ray off.
The only difference I see with x-ray mode is that it picks more elements.
-
-
@thomthom said:
@jim said:
If I do that in x-ray mode, it works. But it fails when I turn x-ray off.
The only difference I see with x-ray mode is that it picks more elements.
Yes, I consider it a failure that I (so far) have not been able to pick an Instance that is nested in another Instance unless X-ray is enabled.
It must be possible?
-
So, you have a reference to a ComponentInstance_ And you want to sniff it out using the pickhelper?
Maybe just some typo bug in your code?
Advertisement