Copy Objects in Group and Remove Copies From Group

Hi

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.

Rhinoscript or Rhino Common solution ok.

Thanks.

Eric

Hi Eric,

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)
2 Likes

Djordje

Thanks for the fast reply. This looks good and it actually will solve some other problems for me like copying the properties, etc. I’ll try it out.

Eric

1 Like

djordje,

This is perfect. Can you explain what this line of code does:

id_c = Rhino.RhinoDoc.ActiveDoc.Objects.Add(obj_c)

I see in the end that you end up with the objects ID. Just trying to understand how it works. Thanks again.

Eric

Hi Eric,

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.

1 Like

Thanks for the explanation. Nice to know one can mix up the two if need be.

Eric

1 Like

Djordje,

Just curious. You seem very knowledgeable. Do you work for McNeel or are you a Developer of some sort? I really appreciate the help you’ve provided.

Eric

1 Like

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.

1 Like