Use PickHelper to find nested Instances?
-
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