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

    Write a python code into a Python Effector

    Cinema 4D SDK
    python
    3
    10
    1.4k
    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 want to insert a code (not written yet) into a python effector I created through a Python script. I figured out how to open the Editor but not how to change the code inside.

      Can you help please ?
      (running on R21)

      import c4d
      from c4d import gui
      from c4d.modules import mograph as mo
      
      def PythonEffector():
          PythonEffector = c4d.BaseList2D(1025800)
          #PythonEffector(c4d.OEPYTHON_OPENEDITOR) >> CHANGE THAT CODE WITH SOMETHING ELSE
          doc.InsertObject(PythonEffector)
          c4d.EventAdd()
      
      # Main function
      def main():
          PythonEffector()
          
      
      
      # Execute main()
      if __name__=='__main__':
          main()
      
      1 Reply Last reply Reply Quote 0
      • H
        Hugo BATTISTELLA
        last edited by

        In fact in this Effector I would like to create an id selection for the operator it will be linked to.

        So I can add this code into the effector

        CairynC 1 Reply Last reply Reply Quote 0
        • CairynC
          Cairyn
          last edited by

          Simply address the code field as a string:

          PythonEffector[c4d.OEPYTHON_STRING] = "# This is some Python code I'd like to see"

          1 Reply Last reply Reply Quote 0
          • CairynC
            Cairyn @Hugo BATTISTELLA
            last edited by Cairyn

            @Hugo-BATTISTELLA said in Write a python code into a Python Effector:

            In fact in this Effector I would like to create an id selection for the operator it will be linked to.

            So I can add this code into the effector

            Not sure whether I understand what you want... but changing the cloner the effector is used in from within the effector seems very unadviseable to me, as an Effector can be used in more than one cloner.

            If you have a specific Cloner in mind, you can access its list of effectors through
            Cloner[c4d.ID_MG_MOTIONGENERATOR_EFFECTORLIST]

            But I guess you mean something else by "operator"...?

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

              TEST_CLONERS_2.c4d

              @Cairyn thank you for answer

              I can now add a line of code but how Can I add multiples lignes of code in the effector. I got some difficulties to manage this.

              What I would like is to make a selection by ID of the cloner through the Python Effector.

              CairynC 1 Reply Last reply Reply Quote 0
              • CairynC
                Cairyn @Hugo BATTISTELLA
                last edited by

                @Hugo-BATTISTELLA said in Write a python code into a Python Effector:

                TEST_CLONERS_2.c4d

                @Cairyn thank you for answer

                I can now add a line of code but how Can I add multiples lignes of code in the effector. I got some difficulties to manage this.

                Basic Python multiline strings?

                PythonEffector[c4d.OEPYTHON_STRING] = (
                    "# This is some Python code I'd like to see\n"
                    "# A second line\n"
                    "import c4d\n"
                    "main()"
                    )
                

                What I would like is to make a selection by ID of the cloner through the Python Effector.

                As far as I can see, there is no way to retrieve the cloner the effector is currently working on from the MoData that you can call up. Have you studied all the examples already? (Linked in the MoData docs)

                See also push_apart_effector.c4d, py_effector_random.c4d and py_effector_shape.c4d scene examples.
                
                1 Reply Last reply Reply Quote 0
                • H
                  Hugo BATTISTELLA
                  last edited by

                  The multilines code works well.

                  Do you mean that there is no possibility to select clones ID to affect them with the Python Effector ?

                  CairynC 1 Reply Last reply Reply Quote 0
                  • CairynC
                    Cairyn @Hugo BATTISTELLA
                    last edited by Cairyn

                    @Hugo-BATTISTELLA said in Write a python code into a Python Effector:

                    The multilines code works well.

                    Do you mean that there is no possibility to select clones ID to affect them with the Python Effector ?

                    uh, you said "ID of the cloner" originally. Not clones.

                    If you want to identify a single clone, you can use the MoData function

                    index = md.GetCurrentIndex()
                    

                    But that's part of the default code in the Python effector already.
                    (And the reference for the current cloner can be read from the predefined variable gen.)

                    1 Reply Last reply Reply Quote 0
                    • ferdinandF
                      ferdinand
                      last edited by ferdinand

                      Hi @Hugo-BATTISTELLA and @Cairyn,

                      thank you for reaching out to us. And thank you @Cairyn for stepping in. We cannot add anything to what @Cairyn already said. We would like however to bring up the fact that topics should be single subject as defined in the Forum Guidelines, as otherwise content will be hard to find for other users. It is fine in this case, but in the future, please open multiple topics for questions that are not direct follow-up questions, but questions with a new scope.

                      Thank you for your understanding,
                      Ferdinand

                      MAXON SDK Specialist
                      developers.maxon.net

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

                        @Cairyn Thank you for your help ! That's it. I confused it all with the wrong word. Sory... Your answers help me very nicely

                        @ferdinand I apologize about going out of the guidelines. I understand this and will create new topic for that point

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