Copy objects independent from group

Hi

I’m using CopyObjects and find that they maintain their grouping with the original group or groups. I want an independent copy maintaining their grouping order but within their own independent groups.

I’m using Rhino 6 with python and willing to use Rhinoscript or Rhino Common.

Eric

I guess I would get the copied objects’ id’s once the copy is made and run RemoveFromAllGroups() on the copies, then create a new group with AddGroup() and add the copied objects to that with AddObjectsToGroup()…

The other thing you could do is go via RhinoCommon, get the base geometry of the objects to copy, then add the objects back to the document - they will not have any group associations in that case - and group them in a new group.

One of my problems is I have no control over how people group objects. Sometimes one, sometimes a series of nested groups. How would I maintain the grouping structure in the copy?

Eric

Can o’ worms… There is no good way to deal with this as not only can objects be in organized nested groups (like a tree), they can also be in overlapping groups and even grouped several times differently. I just don’t see an easy way to get that entire group structure and duplicate it independently. What I outlined should make a new independent ‘flat’ group. Maybe someone else has a better, more sophisticated way…

Hi @eric.bunn, below is a reusable function with some notes how to copy and retain nested groups:

CopyGroupedObjects.py (3.4 KB)

_
c.

1 Like

Thank you. Funny thing is if you copy the group in Rhino manually using ‘Copy’ it creates a unique and independent copy with the grouping structure intact. I could use the Command function and copy it this way but then I need all of the new id’s, which don’t get returned to me. I thought about using SelLast next but I’m nervous about doing it this way.

Eric

IIRC, RhinoScript also handles this correctly.

Hi @eric.bunn, the example posted above returns the ids of the copied objects.

You might look into the methods rs.LastCommandResult and rs.LastCreatedObjects to use _Copy it in a safe way using rs.Command.

_
c.

emilio,

I’m sorry, I’m not sure what IIRC is referring to?

Eric

Clement,

Thanks. I’ll look at those functions.

Eric

IIRC, it means “If I ReCall” or “If I Recall Correctly”

Sorry, didn’t know that.

I believe this will work for me:

ids = rs.GetObjects("Select grouped objects", 0, True, True, True)

if ids:
    rs.Command("_-Copy InPlace")
    rs.UnselectAllObjects()

result = rs.LastCommandResult()
if result==0:
    objs = rs.LastCreatedObjects(True)
else:
    print "The command did not complete."

Hi Eric

It should mean “If I Remember Correctly” … sorry for not being clear.

EDIT

Oh … didn’t see Al’s reply.

Thanks Al !