Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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

    Python Render Token - no frame number?

    Cinema 4D SDK
    r21
    2
    3
    472
    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.
    • CairynC
      Cairyn
      last edited by m_adam

      I was just playing with the render tokens in Python, and I found some strange behavior in the example py_render_token_r21.

      I modified the code a little to give me three different render tokens but the PythonFrameToken function should work the same as the Maxon original. I just added a test for NOTOK here:

      import c4d, time
      
      def PythonFrameToken(data):
          """
              data[4],  # The frame number used for rendering or NOTOK if the frame is not yet recognized.
          """
      
          print "Token $PythonTokenFrm replaced:", str(data[4]), data[4]
          if data[4] == c4d.NOTOK:
              return "NOTOK"
          else:
              return str(data[4])
      
         
      def PythonTimeToken(data):
          return time.strftime("%a in %B") # Weekday in Month
         
          
      def PythonFirstObjectToken(data):
          obj = data[0].GetFirstObject()
          if obj == None:
              return "None"
          else:
              return obj.GetName()
      
                  
      if __name__=="__main__":
          for registeredToken in c4d.modules.tokensystem.GetAllTokenEntries():
              print registeredToken
              if registeredToken.get("_token") in ["PythonTokenFrm", "PythonTokenTime", "PythonTokenFirstObject"]:
                  exit()
      
          c4d.plugins.RegisterToken("PythonTokenFrm", "This Python Token shows the frame", "001", PythonFrameToken)
      
          c4d.plugins.RegisterToken("PythonTokenTime", "This Python Token shows the time", "Sat in June", PythonTimeToken)
      
          c4d.plugins.RegisterToken("PythonTokenFirstObject", "This Python Token shows the name of the first object", "MyObject", PythonFirstObjectToken)
      

      (I am aware of the problem described here:
      https://developers.maxon.net/forum/topic/12162/custom-tokens-with-team-render-server
      so I know this may not work on TeamRender, but I'm working on full GUI C4D so this does not apply.)

      And here's the issue:
      The function PythonFrameToken returns NOTOK in the crucial call. So, the file name ultimately contains "NOTOK" instead of the actual frame number.
      The other two tokens work fine as expected.

      Looking at the console output, PythonFrameToken is called several times; here rendering frame 15-16:

      Token $PythonTokenFrm replaced: -1 -1
      Token $PythonTokenFrm replaced: -1 -1
      Token $PythonTokenFrm replaced: -1 -1
      Token $PythonTokenFrm replaced: 15 15
      Token $PythonTokenFrm replaced: -100000000 -100000000
      Token $PythonTokenFrm replaced: 15 15
      Token $PythonTokenFrm replaced: -100000000 -100000000
      Token $PythonTokenFrm replaced: 15 15
      Token $PythonTokenFrm replaced: 15 15
      Token $PythonTokenFrm replaced: -100000000 -100000000
      Token $PythonTokenFrm replaced: 16 16
      Token $PythonTokenFrm replaced: -100000000 -100000000
      Token $PythonTokenFrm replaced: 16 16
      Token $PythonTokenFrm replaced: 16 16
      

      At some point, data[4] obviously yields the correct value, but the filenames are still wrong.
      It does not matter whether the path string contains a path or just a filename without path component.

      This comes from an official example for R21 though - so I wonder what's wrong.

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

        Hi @Cairyn, this also impacts C++, I don't see any workarounds, unfortunately, I've opened a Bugs report about it.

        Cheers,
        Maxime.

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        CairynC 1 Reply Last reply Reply Quote 0
        • CairynC
          Cairyn @m_adam
          last edited by

          @m_adam Thanks for the confirmation!

          (I swear I'm not doing this on purpose...)

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