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

    i code to create a group of cylinders in C4D python,why no response?

    Cinema 4D SDK
    2
    5
    947
    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.
    • I
      ilad
      last edited by r_gigante

      I am a beginner in C4D python, i want to create a group of cylinders in python,This is my original script, it is simple but wrong, Thank you if you can solve my problem

      import c4d
      
      def create_object(x):
          position = c4d.Vector(x, 0, 0)
          a = c4d.BaseObject(c4d.Ocube)
          a.SetAbsPos(position)
          return a
      
      def main():
      
          for i in range(1,1000,100):
              create_object(i) '''
      

      it should be a line array group of cylinders,the distance of each is 100,but

      No response,i am so sad~

      未命名图片.png

      1 Reply Last reply Reply Quote 0
      • r_giganteR
        r_gigante
        last edited by r_gigante

        Hi ilad, thanks for reaching out us and welcome to our community

        With regard to your issue, there are two main things to note:

        1. the create_object function returns a BaseObject that should be inserted in the active BaseDocument in order to let Cinema make good use of it. The method to look for is BaseDocument::InsertObject();
        2. upon inserting the objects in the scene an EventAdd() should be called in order to inform Cinema that the scene has changed and the events queue needs to be processed.

        Something like the code below should work.

        import c4d 
        
        def create_object(x):
            position = c4d.Vector(x, 0, 0)
            a = c4d.BaseObject(c4d.Ocube)
            a.SetAbsPos(position)
            return a
        
        def main():
            for i in range(1,2000,400):
                doc.InsertObject(create_object(i))
                
            c4d.EventAdd()
        
        

        That said I also recommend you for the future to:

        • use the appropriate category for posting questions making good use of the Read Before Posting ;
        • use the tagging system in order to improve our knowledge-base;
        • use the Question & Answer functionality when posting questions.

        Keep enjoying your discovery of Cinema 4D Python API and feel free to get back with further questions

        Riccardo

        I 1 Reply Last reply Reply Quote 0
        • I
          ilad @r_gigante
          last edited by

          @r_gigante Thank for your kind and high-quality assistance!
          it is such a great forum to study and learn 👍 ☺ ☺

          1 Reply Last reply Reply Quote 0
          • r_giganteR
            r_gigante
            last edited by

            Hi Ilad, I've overlooked one thing here: my notes above are useful if you're running the code as a script in the Script Manager but if you're using a Python generator then you've to return an object in your code that contains all the different cubes and, in this case, the EventAdd() can be skipped.

            Something like this should work:

            import c4d
            
            def create_object(x):
                position = c4d.Vector(x, 0, 0)
                a = c4d.BaseObject(c4d.Ocube)
                a.SetAbsPos(position)
                return a
            
            def main():
                mynull = c4d.BaseObject(c4d.Onull)
                for i in range(1,2000,400):
                    create_object(i).InsertUnder(mynull)
                    
                return mynull
            

            Best, Riccardo

            I 1 Reply Last reply Reply Quote 0
            • I
              ilad @r_gigante
              last edited by

              @r_gigante
              Thank for your professional help! I am so grateful for your commitment!☺ 👍 👍

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