Advertisement
Guest User

Untitled

a guest
Aug 17th, 2013
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. import c4d
  2.  
  3. def main():
  4.     mapping = {}
  5.     context = doc.GetActiveObject() or doc.GetFirstObject()
  6.  
  7.     if not context:
  8.         return
  9.  
  10.     root = context.GetUp()
  11.  
  12.     # Go to the first object in the context.
  13.     while context.GetPred():
  14.         context = context.GetPred()
  15.  
  16.     # Fill the mapping.
  17.     while context:
  18.         mapping.setdefault(context.GetName(), []).append(context)
  19.         context = context.GetNext()
  20.  
  21.     # Create Null-Objects.
  22.     items = sorted(mapping.iteritems(), key=lambda x: x[0])
  23.     prev = None
  24.     for name, objects in items:
  25.         null = c4d.BaseObject(c4d.Onull)
  26.         null.SetName(name)
  27.         for obj in objects:
  28.             doc.AddUndo(c4d.UNDOTYPE_CHANGE, obj)
  29.             obj.Remove()
  30.             obj.InsertUnderLast(null)
  31.         doc.AddUndo(c4d.UNDOTYPE_NEW, null)
  32.         doc.InsertObject(null, root, prev)
  33.         prev = null
  34.  
  35.     c4d.EventAdd()
  36.  
  37. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement