Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import c4d
- def main():
- mapping = {}
- context = doc.GetActiveObject() or doc.GetFirstObject()
- if not context:
- return
- root = context.GetUp()
- # Go to the first object in the context.
- while context.GetPred():
- context = context.GetPred()
- # Fill the mapping.
- while context:
- mapping.setdefault(context.GetName(), []).append(context)
- context = context.GetNext()
- # Create Null-Objects.
- items = sorted(mapping.iteritems(), key=lambda x: x[0])
- prev = None
- for name, objects in items:
- null = c4d.BaseObject(c4d.Onull)
- null.SetName(name)
- for obj in objects:
- doc.AddUndo(c4d.UNDOTYPE_CHANGE, obj)
- obj.Remove()
- obj.InsertUnderLast(null)
- doc.AddUndo(c4d.UNDOTYPE_NEW, null)
- doc.InsertObject(null, root, prev)
- prev = null
- c4d.EventAdd()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement