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 entitiesNow 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_stuffentities are in thesome_entitiescontext 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]...
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register LoginAdvertisement