Group from Selected Entities
-
This is probably covered in the past but how, using ruby, do I group all of the selected components? In other words, programmatically perform a "Make Group"?
-
It's done like this:
model = Sketchup.active_model ent = model.entities sel = model.selection ent.add_group(sel)
You don't want to write it out like this (long way). But this is what the above means(all one line):
Sketchup.active_model.entities.add_group(Sketchup.active_model.selection)
-
Wasn't there potential issues with adding existing entities to groups via the API?
-
@thomthom said:
Wasn't there potential issues with adding existing entities to groups via the API?
There was BUT in recent updates it seems much safer, although if the selection contains groups or instances it's safest to add new instances into the group.entities and erase! the originals to avoid splats...
-
@tig said:
@thomthom said:
Wasn't there potential issues with adding existing entities to groups via the API?
There was BUT in recent updates it seems much safer, although if the selection contains groups or instances it's safest to add new instances into the group.entities and erase! the originals to avoid splats...
But what where the issues in older versions? And workarounds?
I actually have a project where I need to add some existing faces to groups and then manipulate these faces. Faces are connected to other geometry. -
@thomthom said:
@tig said:
@thomthom said:
Wasn't there potential issues with adding existing entities to groups via the API?
There was BUT in recent updates it seems much safer, although if the selection contains groups or instances it's safest to add new instances into the group.entities and erase! the originals to avoid splats...
But what where the issues in older versions? And workarounds?
I actually have a project where I need to add some existing faces to groups and then manipulate these faces. Faces are connected to other geometry.You would sometimes get unexpected BugSplats when grouping an array of entities directly - and you can still do if the array contains instances - it's safest to trap for these and use
add_instance()
on them in the new entities context, using the original instance's transformation, and then erase the original instance to tidy up! Raw geometry will move from anentities
context into agroup.entities
relatively safely IF the group is in theents_array[0].parent.entities
too...
Of course 'cross-threading' entities across different contexts always messes up [still]
However if you only have faces you can usually safely useface_group=entities.add_group(array_of_faces_in_entities)
and they'll be cut fromentities
and go intoface_group
- the faces disappear fromentities
, IF there are someface.edges
that are no longer needed inentities
[because there are no 'dependent' faces left in entities] then these are removed from entities too... BUT if there's an edge in entities that is needed for a face that's moved over intoface_group.entities
AND is still needed for a face that's left behind in entities, then that edge is 'auto-duplicated' in both entities contexts rather than 'moved' from one entities context to another like the face itself... -
cheers
Advertisement