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. esan
    3. Best
    • Profile
    • Following 0
    • Followers 0
    • Topics 4
    • Posts 15
    • Best 1
    • Controversial 0
    • Groups 0

    Best posts made by esan

    • RE: Cant select newly created Instance

      @blastframe Ok was able to retrofit your version to get what I wanted, a bit of guesswork in here, but got the result im after lol

      import c4d
      from c4d import gui
      
      def createInstance():
          obj = op.GetDown()
          inst = c4d.BaseObject(c4d.Oinstance) # created Instance with Base Object
          inst[c4d.INSTANCEOBJECT_LINK] = obj # set Instance's reference link
          # set the name using the object passed to the function
          inst[c4d.ID_BASELIST_NAME] = "%s Instance"%obj[c4d.ID_BASELIST_NAME]
          return inst # return the Instance instance
      
      def AddLongDataType(obj): # create User Data Container named Picker
          if obj is None: return
      
          bc = c4d.GetCustomDataTypeDefault(c4d.DTYPE_LONG)
          bc[c4d.DESC_NAME] = "Picker"
      
          doc.AddUndo(c4d.UNDO_CHANGE, obj)
          obj.AddUserData(bc)
      
          c4d.EventAdd()
      
      def setQuickTab(obj, inst, data): # change User Date container to type Cycle, populate with Children Names
          descid = data[0][0]
          bc = data[0][1]
      
          children = obj.GetChildren()
      
          # Build new cycle options container dynamically
          cycle = c4d.BaseContainer()
      
          for i,child in enumerate(children):
            cycle.SetData(i, child.GetName())
      
          bc[c4d.DESC_CYCLE] = cycle
      
          doc.AddUndo(c4d.UNDO_CHANGE, obj)
          # Set modified description data container
          inst.SetUserDataContainer(descid, bc)
      
      def main(doc):
          obj = doc.GetActiveObject()
          if (obj == None):
              gui.MessageDialog("Please select the Root of the Assets you wish to Instance.")
              return
      
          doc.StartUndo()
          inst = createInstance()
          doc.InsertObject(inst)
          AddLongDataType(inst)
          data = inst.GetUserDataContainer()
          setQuickTab(obj, inst, data)
          
          doc.AddUndo(c4d.UNDO_NEW, inst)
          doc.EndUndo()
          c4d.EventAdd()
      
      if __name__=='__main__':
          main(doc)
      
      posted in Cinema 4D SDK
      esanE
      esan