Is there an extension to instantly access deeply nested geometry?

I am looking for an extension or method to instantly or quickly access the furthest nested group or component in multiple layer wrapped groups.

I am currently using the outliner, but would love a shortcut.

Thanks,
Wade

(1) When you say ā€œmethodā€ do you mean a Ruby method object ?

(2) ā€œAccessā€ is rather vague. There are some shortcuts that extensions can use, to get a reference to nested contexts (group or component instances,) by iterating the modelā€™s singleton definition list collection.
The only way to pass these references to the manual UI is via the selection set.

(3) Is your only selection criteria, the lowest nested context ? And if so, what if there are multiple sibling contexts ? If not, what other criteria would be used ?

(4) Have you explored TTā€™s Selection Toys extension ?

I am sorry for the very late reply, but I didnā€™t know enough until now to understand your questions.

(1) When you say ā€œmethodā€ do you mean a Ruby method object ?

Is there a way to ā€œdouble-click open for editā€ a selected nested group/component with ruby? I havenā€™t had any luck finding a way to do this.

(2) ā€œAccessā€ is rather vague. There are some shortcuts that extensions can use, to get a reference to nested contexts (group or component instances,) by iterating the modelā€™s singleton definition list collection.
The only way to pass these references to the manual UI is via the selection set.

By access I mean getting the same action as double-clicking a group/component to ā€œopenā€ for editing.

(3) Is your only selection criteria, the lowest nested context ? And if so, what if there are multiple sibling contexts ? If not, what other criteria would be used ?

I guess I didnā€™t mean the lowest, just a specific nested group/component.

(4) Have you explored TTā€™s Selection Toys7 extension ?

Yes, but I havenā€™t found what Iā€™m looking for in these tools.

I have been learning Ruby for about 2 months and have just begun experimenting with some simple Ruby inside Sketchup.

You cannot change your active-context this way in the Ruby API.

You can close the active-context and go back one step until you arrive at the parent containerā€™s entities or the model.entities.

model.close_active

But you cannot do the converse - and ā€˜openā€™ a new context as if you are editing it.

The native Outliner lets you do this with a click or two, without having to mine through nested containers one at a timeā€¦

If you want to do an ā€œedit-in-ruby-codeā€ on the entities within a container, then that is quite straightforward in the API - you do not have to edit it per se, just get a reference to its entities: e.g.

group.entities.add_line(pt1, pt2)

Adds a line inside the specified groupā€¦

2 Likes

Sounds good! Thanks for the quick reply.

@TIG & @DanRathbun you both have been such a wealth of knowledge on these threads as I have been shifting through & learning. I owe you both a great thank you.

1 Like

I am trying to figure out a way to iterate through a nested group and control the selection.

I am just beginning to work with loops and I have a simple .times loop that works for a specific nesting situation, but I would like to have better control than the number.

model = Sketchup.active_model
ss = model.selection

3.times do

#Find the definition of the component instance ss[0]. ss[0] is the 1st selection in the selection set 
definition = ss[0].definition

#Get the entities within the component definition.
internal_ents = definition.entities

#Clear the selection set
ss.clear

#Add an array of the internal entities to the selection set.
ss.add internal_ents.to_a 

end

I would really like to be a able to write a loop that would stop with the current selection when the selection lands on a Component (second to the bottom in the image of the outliner).

Would using an ā€œuntilā€ or ā€œwhileā€ conditional work for this? Any help or some pointers would be great!
Thank you.

As long as Iā€™m asking! The next step would be to copy the component and paste it in place outside of the nesting.

If that is the case then opening the instances is not the way you want to do it. How you do things via the UI can often be very different from via a script.

For instance, if you want to copy an instance you click on into the root context then you can create a Ruby tool and use the pick helper to pick instances in the model. The pick helper will also give you the transformation for the pick. Using that you can add a new instance entities.add_instance using a transformation which will place it in a visual identical position as the one you picked.

(This is a good example of including your desired result when asking programming questions - as the solution to your end result might be different that the path youā€™re looking at.)

1 Like

Thank you very much!

I think your post help reaffirm that I am in a little over my head already with problems I am trying to solve with ruby.

I think I should get some more basic ruby/Sketchup API fundamentals under my belt!

The SketchUp API simply adds modules and classes to Ruby. It really helps to learn Ruby first. (Other topics)

Such as iterating standard Ruby collection classes (Array, Set, Hash.) Many of the iterator methods are not documented in the SketchUp API docs, they are documented in the Ruby docs:
http://ruby-doc.org/core-2.0.0

Also, regarding your ā€œselectionā€ problem above, ā€¦it is likely not safe to push references to objects in different contexts, into the SketchUp selection collection. (ā€¦ if it is even allowed.)

EDIT: But you can push whatever references you have into your own collections (Array, Hash, whatever.)

There is a thread in which Iā€™ve already posted iterator code to find components and groups by name.

(Moving to the Ruby API category.)

1 Like

Thank you, Dan. I will check that stuff out!