Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login
    1. Maxon Developers Forum
    2. John_Do
    3. Best
    • Profile
    • Following 0
    • Followers 0
    • Topics 9
    • Posts 33
    • Best 1
    • Controversial 0
    • Groups 0

    Best posts made by John_Do

    • RE: Copy children to selection with GetClone()

      Hi @ferdinand, thanks for the feedback, I've got it working with your suggestion. The method B was correct but the undo part was wrong ( the undo step was applied on the original objects instead of the new ones, thus leading to a mess when performing an undo). I also added the bit part to keep new objects folded in the OM. Here is the code :

      # CopyDeformers
      
      import c4d
      
      doc = c4d.documents.GetActiveDocument()
      
      
      def main():
      
          doc.StartUndo()
      
          objs = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER)
      
          if len(objs) >= 2:
              # Get the last selected object
              active = objs.pop(-1)
      
              # Get the deformers
              deformers = [i for i in active.GetChildren()]
      
              # Copy deformers to selection
              if deformers:
                  for o in objs:
                      for d in deformers[::-1]:
                          dcopy = d.GetClone(c4d.COPYFLAGS_NO_BITS)
                          doc.InsertObject(dcopy, parent=o)
                          doc.AddUndo(c4d.UNDOTYPE_NEW, dcopy)
                      o.SetBit(c4d.BIT_MFOLD)
      
          doc.EndUndo()
      
          c4d.EventAdd()
      
      
      if __name__ == '__main__':
          main()
      
      
      posted in Cinema 4D SDK
      John_DoJ
      John_Do