Group the selected entities and give them a name[Solved]
-
I want to automate following event with a script:
I group the selected entities, right click: "Elementinformation" and enter a name like "result"...
So, that's what I already have:
model = Sketchup.active_model selection = model.selection # all the selected entities
Now I want to add a group, give them a name and add "selection" to the group:
group = model.add_group group.name = "result" group.entities. ... (?)
How can I add the "selection" to that group? It tried a lot, but without success
Do you have a tip what can I do?
Thanks a lot for your help!
-
In the index for [Code Snippets] by Subject there is this entry:
-
@dan rathbun said:
In the index for [Code Snippets] by Subject there is this entry:
absolutely perfect! That's it!
Thanks a lot!
Just for other interested people:
model = Sketchup.active_model selection = model.selection.to_a group = model.active_entities.add_group(selection) group.name = "result"
-
Just out of curiosity, is there any significance in the white space between "...to_a" and "group=model.active......"?
-
Nothing!
Just to make reading it easier ?Note that
gp=some_entities.add_group(some_stuff)
is ONLY successful if all of thesome_stuff
entities are in thesome_entities
context AND it's the active_entities: otherwise you'll Bugsplat!
So it's fine when you are adding a selection to a group in the same entities - as to select them they must all be in the same [active] entities context and you make the new group in that context too.
Just be wary of grouping groups and adding things that are in one context into another context - to do that IS possible but involves either complex 'cloning' of geometry OR getting the definition of groups/instances and repeating their instances [temporarily] in the new context before erasing the original one[s]...
Advertisement