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

    LINK EFFECTORS TO CLONERS

    Cinema 4D SDK
    python
    3
    4
    823
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Hugo BATTISTELLA
      last edited by

      Hello,
      I'm very new on python and I would like to know how to link the "pyhton effector" I create in this exemple to the cloner. I tried to use the InsertObject function but it seems that it's not working. TEST_CLONERS_1.c4d

      I run on R21

      Can you help ?

      import c4d
      from c4d import gui
      from c4d.modules import mograph as mo
      
      def cloner_creation():
          Cloner = c4d.BaseList2D(1018544)
          Cloner[c4d.ID_MG_MOTIONGENERATOR_MODE] = 3
          Spheres = c4d.BaseList2D(5160)
      
          doc.InsertObject(Cloner)
          doc.InsertObject(Spheres)
          Spheres.InsertUnder(Cloner)
      
      
      
      def effectorsCreation():
          Effector = c4d.BaseList2D(1025800)
          
          EffectorList = c4d.InExcludeData() # Initialize an InExclude data
          
          Cloner.InsertObject(EffectorList) # Add effector to effectors list
          doc.InsertObject(Effector)
      
      # Main function
      def main():
          cloner_creation()
          effectorsCreation()
          c4d.EventAdd()
      
      
      # Execute main()
      if __name__=='__main__':
          main()
      
      1 Reply Last reply Reply Quote 0
      • B
        bentraje
        last edited by

        Hi,

        Not quite directly a revision of your code but this should help you get started.

        import c4d
        from c4d import gui
        
        # Main function
        def main():
            cloner = doc.SearchObject("Cloner") # Assuming there is already a Cloner Mograph Object 
            plain_effector = doc.SearchObject("Plain")# Assuming there is already a Plain Effector Object 
        
            effector_list = c4d.InExcludeData()
            effector_list.InsertObject(plain_effector, 1)
        
            cloner[c4d.ID_MG_MOTIONGENERATOR_EFFECTORLIST] = effector_list
            c4d.EventAdd()
        
        
        # Execute main()
        if __name__=='__main__':
            main()
        
        1 Reply Last reply Reply Quote 2
        • ferdinandF
          ferdinand
          last edited by ferdinand

          Hi @Hugo-BATTISTELLA,

          thank you for reaching out to us and thank you @bentraje for providing help.

          The major problem with your code is that you have the line Cloner.InsertObject(EffectorList) in there. But there is no variable of the name Cloner within the scope of effectorsCreation. Which is why your code will raise a NameError on this line. But even if the variable Cloner from your function cloner_creation would be visible within effectorsCreation, it would still raise an AttributeError, because your Cloner is of type BaseObject which has no attribute (i.e., method) of the name InsertObject.

          I would also recommend not to insatiate an c4d.InExcludeData from scratch, because you will lose any existing links by doing so and then writing back that newly allocated InExcludeData. In this case here it does not really matter, since you also instantiate the MoGraph cloner, i.e., its effectors list will still be empty. Below you can find a commented section of your code and a proposal how I would write something like that (which is effectively also what @bentraje did).

          Cheers,
          Ferdinand

          The code:

          import c4d
          
          # This is a lightly commented version of your code, pointing out the major
          # problem with your version.
          """
          def effectorsCreation():
              Effector = c4d.BaseList2D(1025800)
              # This does not do anything; it just creates an InexCludeData instance.
              EffectorList = c4d.InExcludeData() # Initialize an InExclude data
          	
              # That does not work, Cloner is not visible in this scope, it would also
              # be an BaseObject, which does not have a InsertObject method.
              Cloner.InsertObject(EffectorList) # Add effector to effectors list
              doc.InsertObject(Effector)
          """
          
          def CreateClonerSetup():
              """
              """
              # Instantiate a MoGraph cloner and Python effector. One can also use
              # BaseList2D.__init__(), this version here is just more verbose.
              cloner = c4d.BaseObject(1018544)
              effector = c4d.BaseObject(1025800)
              
              # Get a copy of the InExcludeData Effectors parameter of the cloner.
              inExcludeData = cloner[c4d.ID_MG_MOTIONGENERATOR_EFFECTORLIST]
              # Add the effector in an activated state (1)
              inExcludeData.InsertObject(effector, 1)
              # Important, we have to write the modified InExcludeData back, since we
              # only retrieved a copy of it.
              cloner[c4d.ID_MG_MOTIONGENERATOR_EFFECTORLIST] = inExcludeData
              
              # Add both nodes to the currently active document.
              doc.InsertObject(effector)
              doc.InsertObject(cloner)
              
              # Update Cinema 4D.
              c4d.EventAdd()
          
          if __name__=='__main__':
              CreateClonerSetup()
          

          MAXON SDK Specialist
          developers.maxon.net

          1 Reply Last reply Reply Quote 1
          • H
            Hugo BATTISTELLA
            last edited by

            Thank you @bentraje and @ferdinand !

            You make the deal of the EffectorList function much clearer ! It works well now

            1 Reply Last reply Reply Quote 0
            • First post
              Last post