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

    Add Expression Value in Render Settings Save Path

    General Talk
    chit-chat programming learning-resource
    5
    9
    2.0k
    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.
    • G
      Gemini
      last edited by

      Hello,
      Is there a chance to add an expression result of python ( for me the mayor version from the C4D file name ) to the Render Settings Path string ? I would not use c++ custom token, because I'm not familiar in C++. 😉
      Thanks ! 🙂
      G
      f1d6599a-bfb8-4ab8-9ba9-4041b9a7a092-image.png

      DunhouD i_mazlovI 2 Replies Last reply Reply Quote 0
      • DunhouD
        Dunhou @Gemini
        last edited by

        Hey @Gemini ,

        You should take a look at py-render-token example, and filter the version number of your project like re.findall("v"+"\d+",filePath) if I understand not wrong.

        Cheers~
        DunHou

        https://boghma.com
        https://github.com/DunHouGo

        minakristoferM 1 Reply Last reply Reply Quote 2
        • i_mazlovI
          i_mazlov @Gemini
          last edited by

          Hi @Gemini,

          Welcome to the Maxon developers forum and its community, it is great to have you with us!

          Getting Started

          Before creating your next postings, we would recommend making yourself accustomed with our forum and support procedures. You did not do anything wrong, we point all new users to these rules.

          • Forum Overview: Provides a broad overview of the fundamental structure and rules of this forum, such as the purpose of the different sub-forums or the fact that we will ban users who engage in hate speech or harassment.
          • Support Procedures: Provides a more in detail overview of how we provide technical support for APIs here. This topic will tell you how to ask good questions and limits of our technical support.
          • Forum Features: Provides an overview of the technical features of this forum, such as Markdown markup or file uploads.

          It is strongly recommended to read the first two topics carefully, especially the section Support Procedures: Asking Questions.

          About your First Question

          There's no built-in token for this, so you would need to manually parse the document file path for the necessary information (e.g. using regular expressions) and adjust the render settings correspondingly.

          Depending on the desired behavior you'd like to achieve, the implementation can be slightly different.

          If you'd like to create custom token, which contains your extracted information, please check the posting from Dunhou (thanks for taking an active role in the community!).

          In case you'd like to have a script that asjusts the filepath, please have a look at the render settings example. For the "File" field you'd need to use c4d.RDATA_PATH token.

          Cheers,
          Ilia

          MAXON SDK Specialist
          developers.maxon.net

          1 Reply Last reply Reply Quote 0
          • G
            Gemini
            last edited by

            Thanks for your answer.
            Tokens are working well but I have a strange issue with them at the multi pass files, if I end the file with a string ( here 'XXX') the file works well but If not it adds '1' to it. Do I miss something in the process ? I think my python token string could not generate that end string there.

            image.png

            1 Reply Last reply Reply Quote 0
            • G
              Gemini
              last edited by Gemini

              """
              Copyright: MAXON Computer GmbH
              Author: Maxime Adam
              
              Description:
                  - Registers two Tokens plugin. One visible in the render setting the other one not.
                  - A token is a string that will be replaced during the token evaluation time by a string representation.
              
              Class/method highlighted:
                  - c4d.plugins.RegisterToken
                  - c4d.plugins.RegisterHiddenToken
              
              """
              import c4d
              import re
              from c4d import documents
              
              def majorVersionToken(data):
                  """The function that will be called to return the string representation of a token.
              
                  Args:
              
                  Returns:
                      str: The string that will replace the token
                  """
                  doc = documents.GetActiveDocument()
                  # Get the file path of the current document
                  file_name = doc.GetDocumentName()
                  match = re.search(r'v\d{0,10}', file_name)
                  version = 'v001'
                  if match:
                      version = 'v' + match.group().replace('v','').zfill(3)
                  else:
                      # print("No match found")
                      pass
                  return str(version)
              
              def minorVersionToken(data):
                  """The function that will be called to return the string representation of a token.
              
                  Args:
              
                  Returns:
                      str: The string that will replace the token
                  """
                  doc = documents.GetActiveDocument()
                  # Get the file path of the current document
                  # file_path = doc.GetDocumentPath()
                  file_name = doc.GetDocumentName()
                  match = re.search(r'_\d{0,10}', file_name)
                  version = '001'
                  if match:
                      version = match.group().replace('_','')
                      if len( version) <= 3:
                          version = version.zfill(3)
                  else:
                      pass
                  return str(version)
              
              def shortProjectNameToken(data):
                  """The function that will be called to return the string representation of a token.
              
                  Args:
              
                  Returns:
                      str: The string that will replace the token
                  """
                  # Get the file path of the current document
                  file_name = documents.GetActiveDocument().GetDocumentName()
                  match = re.search(r'v\d{0,3}', file_name)
                  token = file_name.split( match.group())[0].rstrip('_')
                  return str(token)
              
              
              def PythonHiddenToken(data):
                  """The function that will be called to return the string representation of a token.
              
                  Args:
              
                  Returns:
                      str: The string that will replace the token
                  """
              
                  # Returns the frame number as a string. So this will replace the token by the frame number.
                  return str(data[4])
              
              
              if __name__ == "__main__":
                  # First it's important to check if the token is not already registered
                  for registeredToken in c4d.modules.tokensystem.GetAllTokenEntries():
                      # Checks if the token name is already used, if it's the case exit.
                      if registeredToken.get("_token") in ["majorVersionToken", "PythonHiddenToken"]:
                          exit()
              
                  # Registers the token "PythonToken" that will be visible in te render setting.
                  c4d.plugins.RegisterToken("mver", "_Project Mayor Version", "v002", majorVersionToken)
                  c4d.plugins.RegisterToken("nver", "_Project Minor Version", "002", minorVersionToken)
                  c4d.plugins.RegisterToken("shortproject", "_Project Short Name", "scene", shortProjectNameToken)
              
                  # Registers the token "PythonHiddenToken" it will not be visible in te render setting.
                  c4d.plugins.RegisterHiddenToken("PythonHiddenToken", "This is a Hidden Python Token", "001", PythonHiddenToken)
              
              1 Reply Last reply Reply Quote 0
              • S
                shivamist
                last edited by

                If i'm not mistaken, "_1" is generated by Redshift if the "Regular Image" filename and the "Multi-Pass Image" filename are the same

                Same filename :
                image.png
                image.png

                Changing "-" to "_" at the end of the file :
                image.png
                eb647411-aa3c-4870-9f36-245afe77310f-image.png

                1 Reply Last reply Reply Quote 0
                • G
                  Gemini
                  last edited by

                  Ups. Maybe. I'm checking..

                  1 Reply Last reply Reply Quote 0
                  • G
                    Gemini
                    last edited by

                    The extension is different. So the file name too.
                    image.png

                    1 Reply Last reply Reply Quote 0
                    • minakristoferM
                      minakristofer @Dunhou
                      last edited by

                      @Dunhou It seems corect! Well done.

                      Data Recovery Software

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