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

    Need help getting an old script to work in C4D

    Cinema 4D SDK
    python
    3
    8
    886
    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.
    • B
      bstone
      last edited by bstone

      Hey all, I found this post from 11+ years ago by a user named
      "bandini" that has a bit of code to bake animations. I am trying to update the code so that it works with the current version of C4D. Any help would be appreciated! Thanks!

      https://forums.cgsociety.org/t/holy-grail-bake-mograph-objects-to-keyframes/1296975/10

      This is what I've converted so far but I am receiving an error on line 11 that says:
      in <module>
      while current_frame <= user_end_time:
      NameError: name 'StopAllThreads' is not defined

      Here is the "updated" script that is giving me the error

      user_start_time = 0
      user_end_time = 90
      
      fps = doc.GetFps()
      bake_start_time = doc.GetTime()  # needed to initialize a BaseTime object
      
      doc.SetTime(bake_start_time)  # set the time slider to the user's start time
      current_frame = doc.GetTime().GetFrame(fps)
      
      while current_frame <= user_end_time:
          StopAllThreads()
          CallCommand(12410)  # record
          user_start_time += 1
          doc.SetFrame(user_start_time)  # Set the current frame of the time slider
          redraw = DrawViews(DA_STATICBREAK)
          EventAdd(EVENT_ANIMATE)
          if redraw:
              current_frame = doc.GetTime().GetFrame(fps)
      
      1 Reply Last reply Reply Quote 0
      • B
        bentraje
        last edited by

        Maybe add c4d? Like c4d.StopAllThreads() ?

        1 Reply Last reply Reply Quote 0
        • B
          bstone
          last edited by

          When I try that, I get an error that says "NameError: name 'c4d' is not defined"

          1 Reply Last reply Reply Quote 0
          • B
            bentraje
            last edited by

            because your have to add
            import c4d
            at the start of every c4d script.

            1 Reply Last reply Reply Quote 0
            • B
              bstone
              last edited by

              Thank you, by adding the "import c4d" at the beginning of the script and "c4d." in front of the lines below, that solved the issues with the
              StopAllThreads()
              CallCommand(12410) # record

              However, now line 16 says:
              line 16, in <module>
              c4d.SetFrame(user_start_time) # Set the current frame of the time slider
              AttributeError: module 'c4d' has no attribute 'SetFrame'

              1 Reply Last reply Reply Quote 0
              • B
                bstone
                last edited by

                Here are the scripts (original and modified), as well as the c4d file if that is helpful

                https://www.dropbox.com/sh/vwnkj9x08b9dg0k/AACWhSoQV4rYo3ECMkNIZ2Kda?dl=0

                1 Reply Last reply Reply Quote 0
                • B
                  bentraje
                  last edited by

                  Hi @bstone

                  Thanks for providing the modified script.
                  API changed throughout the release. One of those probably is the SetFrame (i.e no longer exist).

                  Here's what I have.

                  import c4d
                  
                  user_start_time = 0
                  user_end_time = 90
                  
                  fps = doc.GetFps()
                  bake_start_time = doc.GetTime()  # needed to initialize a BaseTime object
                  
                  doc.SetTime(bake_start_time)  # set the time slider to the user's start time
                  current_frame = doc.GetTime().GetFrame(fps)
                  
                  while current_frame <= user_end_time:
                      c4d.StopAllThreads()
                      c4d.CallCommand(12410)  # record
                      user_start_time += 1
                      #doc.SetFrame(user_start_time)  # Set the current frame of the time slider
                      pTime = c4d.BaseTime(user_start_time,fps)
                      doc.SetTime(pTime)
                      redraw = c4d.DrawViews(c4d.DA_STATICBREAK)
                      c4d.EventAdd(c4d.EVENT_ANIMATE)
                      if redraw:
                          current_frame = doc.GetTime().GetFrame(fps)
                  
                  ferdinandF 1 Reply Last reply Reply Quote 0
                  • ferdinandF
                    ferdinand @bentraje
                    last edited by

                    Hello @bstone,

                    Thank you for reaching out to us and welcome to the Cinema 4D community. And thank you @bentraje for answering the question. We do not have to add anything here, @bentraje already pointed out all the important bits 🙂
                    Cheers,
                    ferdinand

                    MAXON SDK Specialist
                    developers.maxon.net

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