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

    Get rotation of animated object with python

    Cinema 4D SDK
    python windows
    2
    2
    640
    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.
    • A
      Anchorage
      last edited by

      Hi
      I'm trying to write python script for Cinema4D R17 that would go through all frames and output rotation of object that is animated. The script works but it always returns the same rotation even when object is animated and its rotation is changing in each frame. How do I fix this?

      Here is the code I'm using

      import c4d
      import c4d.utils
      import math
      from c4d import gui
      
      def main():
          currentDoc = c4d.documents.GetActiveDocument()
          docFps = currentDoc.GetFps()
          lastFrame = currentDoc.GetMaxTime().GetFrame(docFps)
          
          print "Document framerate is " + str(docFps)
          print "Last frame is " + str(lastFrame)
      
          for x in range(0, lastFrame + 1):
              currentDoc.SetTime(c4d.BaseTime(x, docFps))
              c4d.EventAdd()
              cubeObj = currentDoc.SearchObject("Cube")
              cubeObjRotation = cubeObj.GetAbsRot()
              cubeObjRotation = cubeObjRotation * 180 / math.pi
              print "Frame" + str(x) + " - Cube rotation is " + str(cubeObjRotation)
              
      if __name__=='__main__':
          main()
      
      1 Reply Last reply Reply Quote 0
      • a_blockA
        a_block
        last edited by

        Hi,

        don't be surprised, I have turned your thread into a question.

        The problem is, that the document will actually not be animated (or lets rather say, it will not be evaluated or executed) when calling SetTime(). Additionally you need to call ExecutePasses().
        The BaseDocument manual in our C++ SDK documentation contains some extra information on this topic in the sections Time and Animate.

        Cheers,
        Andreas

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