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

    Create New Take Using Python

    Cinema 4D SDK
    4
    9
    1.7k
    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.
    • D
      davidtodman
      last edited by m_adam

      Hi,

      I'm very new to C4D python and am having trouble doing the simplest thing. Eventually I want to create a script that controls quite a few things related to Takes. However, my first baby step is simply to create a new Take and add it to the list.

      My first attempt seems to work but when I right-click my new take I cannot delete it and certain behaviours crash C4D! Can someone tell me what I am doing wrong, as I've copied most of this script from a Cineversity script that seems to behave just fine.

      def main():
          td = doc.GetTakeData()
          pt = td.GetMainTake()
          ct = td.SetCurrentTake(pt)
          nt = td.AddTake("",pt,pt)
          td.InsertTake(nt,pt,2)
          td.SetCurrentTake(nt)
          nt.SetName("My Take")
          c4d.EventAdd()
      

      Any help is much appreciated.

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

        Hi,

        welcome to the forum. Your major mistake is to try to clone the main take which apparently is meant to be unique.

        Cheers,
        zipit

        """ This will clone the first take after the main take and insert it as a new
        take.
        """
        
        import c4d
        
        def main():
            """
            """
            take_data = doc.GetTakeData()
            # This is the top most take node in the take window. It cannot be deleted
            # and basically is only there to "bind all the other takes together".
            main_take = take_data.GetMainTake()
            # Its first child which is the first "actual" take.
            child_take = main_take.GetDown()
        
            if child_take is None:
                msg = "Please insert at least one take to clone."
                raise RuntimeError(msg)
        
            # Not really needed.
            # current_take = take_data.SetCurrentTake(main_take)
        
            # Creates a new take and inserts it. The first argument is the name of
            # the node (which does not seem to work), the second the insertion point
            # and the third the cloning template. When you clone here from the main
            # take, you will get a "second main take", i.e. one that is not 
            # deletable and you probably will confuse the heck out of Cinema.
            new_take = take_data.AddTake("", main_take, child_take)
            new_take.SetName("Bob is your uncle.")
        
            # We do not need to invoke TakeData.InsertTake().
        
            # Set the new take as the active one and tell Cinema that we did
            # poke around in the scene graph.
            take_data.SetCurrentTake(new_take)
            c4d.EventAdd()
            
        if __name__ == "__main__":
            main()
        

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 1
        • D
          davidtodman
          last edited by

          Hi @zipit . Thank you so much for your help. I don't think I would have ever figured this out for myself!

          1 Reply Last reply Reply Quote 0
          • D
            davidtodman
            last edited by

            Out of interest - How did you learn C4D Python? I can't find any ground up courses or tutes. They're either too advanced for beginners or so basic they just show you how to drag and drop commands from the script log.

            I've already taken a general python course. But I find the structure of C4D python baffling and need some help understand the basic structure of data in the program.

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

              Hi,

              Python was not my first programming language, so I sort of had a heads start. Learning a programming language is always a painful process to some degree, just like for a natural language. The only thing that helps is practice. I am also not too convinced about the quality or general helpfulness of programming language books or tutorials, they are usually a mess IMHO.

              But you are probably more after learning the Python standard libraries and the Cinema API, not the principal syntax of Python.

              There are for once a collection of sort of narrative scripts by Maxon which explain the basics of their classic API. And I know that @Cairyn has some Python stuff on Patreon. I have never seen the content, its probably also classic API only, but judging from his posts here, he seems to put quite some work into it. And then there is of course Cineversity, but that you already know.

              Getting to know APIs can only achieved by practice in the end. The first time doing it might be a bit daunting, but you will see its not so bad in the end. Just dive in and prepare for some bruises in the beginning 😉

              Cheers,
              zipit

              MAXON SDK Specialist
              developers.maxon.net

              D 1 Reply Last reply Reply Quote 1
              • M
                m_adam
                last edited by m_adam

                Hi @davidtodman first of all welcome to the plugincafe community 🙂

                I would like to point you to few rules for your next topics (I've set up this one correctly, but don't worry this is your first topic)

                • How to Post Questions (Especially the Tagging and Category part)
                • Q&A New Functionality

                @zipit already provide you the answers, but I just wanted to point you to take_system Github repository where you can find several examples about the Take system, finally, I know it's C++ but you will see the code is very similar and you can find more verbal information about the Take system in Take System Overview.

                With that's said I guess we all agree that for the moment the best way to learn the Cinema 4D API is to simply practice and ask questions here whenever there is something you don't understand.

                Cheers,
                Maxime.

                MAXON SDK Specialist

                Development Blog, MAXON Registered Developer

                D 1 Reply Last reply Reply Quote 0
                • D
                  davidtodman @ferdinand
                  last edited by

                  @zipit Thank you for taking the time to reply. Much appreciated.

                  1 Reply Last reply Reply Quote 0
                  • D
                    davidtodman @m_adam
                    last edited by

                    @m_adam Thanks for your help. Apologies for not following the rules. I'm struggling with the rules of Python at the moment so it's not surprising! Will try to be a better poster in future.

                    1 Reply Last reply Reply Quote 0
                    • I
                      IslaDuffy
                      last edited by IslaDuffy

                      This post is deleted!
                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post