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

    Troubleshooting Safe Frame Calculations Across Different Takes in Cinema 4D

    Cinema 4D SDK
    python
    2
    3
    688
    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.
    • F
      Futurium
      last edited by

      Hi,

      I want to calculate the safe frame value for all takes, where each take has a different camera and possibly different render settings. If I manually change a take and run my code, it returns the same safe frame for all other takes as for the currently selected one, which is incorrect in my case. It seems the values used for safe frame calculations are not being updated when I iterate through takes via code. What am I missing? I've attached a simple test scene to test the code.

      Best regards,
      Tomasz

      import c4d
      
      def grab_children_of_main_take(take_data):
          children = []
          mainTake = take_data.GetMainTake()
          take = mainTake.GetDown()
      
          while take is not None:
              children.append(take)
              take = take.GetNext()
      
          return children
      
      def get_safe_frame_for_the_current_per_take(doc):
          bd = doc.GetRenderBaseDraw()
          safeframe = bd.GetSafeFrame()
          print(safeframe)
      
      
      def main():
          c4d.CallCommand(13957)  # Clear Console
          doc = c4d.documents.GetActiveDocument()
          take_data = doc.GetTakeData()
          if take_data is None:
              raise RuntimeError("Failed to retrieve the take data.")
      
          children_of_main_take = grab_children_of_main_take(take_data)
          print("Returned : " + str(len(children_of_main_take)) + " children of main take")
      
          for child_take in children_of_main_take:
              take_data.SetCurrentTake(child_take)
              doc.ExecutePasses(bt=None, animation=True, expressions=True, caches=True, flags=c4d.BUILDFLAGS_NONE)
              current_camera = child_take.GetCamera(take_data)
              print("\n--------------------------------------------------")
              print(f"Checking take {child_take.GetName()} with camera {current_camera.GetName()}")
              get_safe_frame_for_the_current_per_take(doc)
      
      if __name__ == '__main__':
          c4d.CallCommand(13957)  # Clear Console
          main()
      

      SafeFrameWithTakes.c4d

      i_mazlovI 1 Reply Last reply Reply Quote 0
      • i_mazlovI
        i_mazlov @Futurium
        last edited by i_mazlov

        Hi Tomasz,

        You need to use function DrawViews() to update the document BaseDraw that is used for SafeFrame calculation. ExecutePasses updates the document but does not initiate view redraw.

        Just try your script with the following line instead of ExecutePasses function call:

        c4d.DrawViews(c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW | c4d.DRAWFLAGS_NO_THREAD | c4d.DRAWFLAGS_STATICBREAK)
        

        You can have a closer look to our basedocument_animate_r13.py example.

        By the way, it also wouldn't hurt to call c4d.EventAdd() at the very end of your script to initiate GUI update.

        Cheers,
        Ilia

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 0
        • F
          Futurium
          last edited by

          Thank you @i_mazlov

          It works perfectly 🙂

          Best regards,
          Tomasz

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