How to back out of editing a component ? in Ruby

Editing a nested component, how can one programatically exit the editing mode and go in the root Model context editing.

Hi nekitu, hi folks.

Four way come to my mind:

1 - Click in empty space outside of the context delimiting box of the first component in the hierarchy.

2 - Right click in empty space in the context delimiting box of the component being edited and chose Close Component in the contextual menu that appears after the right click.

3 - Press the Escape key repeatedly to get back to the root of the model.

4 - Click on the file name at the top of the component list in the Outliner Window.

Probably one of these can be programmed in Ruby.



:slight_smile: reading your solutions I thought you misunderstood, but the last line made it clear :), so there is no direct API way I guess? like some sort of Sketchup.editRootModel() :slight_smile:

There is a way.

Let’s assume your user activates your extension whilst they are inside a group or component-instance edit context.

This line of code moves you back into the model’s base-level entities…

model.close_active until model.entities == model.active_entities

Alternatively just use model.entities as the ‘destination’ context ??

It depends on what you want to do.

Do NOT try to make groups directly from entities[.to_a] in anything but the model.active_entities context !
Use group = entities.add_group() then add objects into group.entities - note how these must be raw geometry etc, or brand new instances of groups or components - and not direct references from another non-active entities context…