I’m selecting a group of objects with GetObjects using Python in Rhino 5, copying the objects using CopyObjects and finding that the copies are within the group I’ve selected. I want to remove them from the group and put them into their own group. I need a way to pull the group name from the selection so I can extract them from the group.
I would “bake” the objects through rhinocommon instead of using ‘rs.CopyObjects’.
Pay attention that each time you run script, new objects will be added to the same “group_c”:
import rhinoscriptsyntax as rs
import Rhino
id_L = rs.GetObjects("select objs from Rhino", group=True)
id_c_L = []
for id in id_L:
# copy
obj_c = rs.coercegeometry(id)
# bake
id_c = Rhino.RhinoDoc.ActiveDoc.Objects.Add(obj_c)
id_c_L.append(id_c)
# optionally copy properties
# layer
layName = rs.ObjectLayer(id)
rs.ObjectLayer(id_c, layName)
# color
color = rs.ObjectColor(id)
rs.ObjectColor(id_c, color)
# name
name = rs.ObjectName(id)
rs.ObjectName(id_c, name)
# group
groupName = "group_c"
allGroupName_L = rs.GroupNames()
if groupName not in allGroupName_L:
rs.AddGroup(groupName)
rs.AddObjectsToGroup(id_c_L, groupName)
The geometry you see in Rhino viewports are Rhino Objects. They have properties, one of them being the geometry itself. We “extracted” the geometry of the Rhino object with “rs.coercegeometry”.
Then we added that geometry to the Rhino document in order to create a new Rhino object - in jargon “baking”. So whenever you add a geometry to Rhino document, you are creating a Rhino object.
In the line above this is Rhino’s document: rhinoDoc = Rhino.RhinoDoc.ActiveDoc
When baking, an id of the newly created Rhino object is returned (‘id_c’) in this case.
The reason for the confusion was because I mixed rhinoscriptsyntax with RhinoCommon. Sorry for that.
Hi Eric,
Thank you for the compliments, but I am not so knowledgeable, so take my answers with caution.
This forum (and the older ones) are such a great place, because there are plenty of people who help users with their issues. Everyday Rhino users, along with McNeel developers.
I also ask questions related to my problems here, and regularly get instant replies - solutions.
I am not a developer. I work for a facade company as an engineer. Visiting McNeel forum helps me learn new things about Rhino, and prevents me from forgetting the old ones.