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

    How to set completely custom render output filename?

    Cinema 4D SDK
    python
    4
    6
    1.7k
    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.
    • jcooperJ
      jcooper
      last edited by r_gigante

      From what I can tell, RDATA_PATH only refers to a directory. In order to integrate C4D into our pipeline, I need our code to be in complete control of the naming scheme of the filenames of the rendered files that will go in that directory. How do I do that in Python?

      I can't find anywhere to specify that the rendered filenames should be something like:

      "shot0250_lighting_beauty_v003.####.exr"

      Where "####" would be replaced by a four-digit frame number. Bear in mind that the scene files themselves may have a naming scheme slightly different from the naming scheme for the rendered output files, so I can't allow C4D to "automatically" construct the filenames for me all on its own.

      JOHN COOPER I TECHNICAL DIRECTOR
      PSYOP LA

      1 Reply Last reply Reply Quote 0
      • P
        PluginStudent
        last edited by

        Hi,

        Cinema has a programmable Token system that can be used to define parts of the final file name

        • Variable Path and File Names
        • Token System Overview
        • c4d.modules.tokensystem
        1 Reply Last reply Reply Quote 1
        • r_giganteR
          r_gigante
          last edited by

          Hi @jcooper and @PluginStudent, thanks for reaching out us and welcome to the Plugincafé community!

          All the topics suggested by @PluginStudent - kudos dude - are pertinent to address your issue and you should be ready to go. Nonetheless, if any further doubts arise, just follow up here.

          Last but not least, for the future I warmly recommend to make use of the thread tagging system in order to improve our community knowledge-base readability.

          Best, Riccardo

          1 Reply Last reply Reply Quote 0
          • jcooperJ
            jcooper
            last edited by

            Okay, thanks. I guess what wasn't clear (to me) from the documentation was that the RDATA_PATH (and presumably the RDATA_MULTIPASS_FILENAME as well) are full paths that include a filename component.

            Follow-up questions:

            1. How do I control how much zero-padding is used for the $frame token? We typically use 4-digit, zero-padded frame tokens, but what if a situation called for, say, 6 digits?

            2. How do I get at the RenderData for a specific renderer such as Redshift? For instance, it has its own "filename" attribute, but I don't know how to access/modify it from the python API.

            Thanks!

            JOHN COOPER I TECHNICAL DIRECTOR
            PSYOP LA

            r_giganteR 1 Reply Last reply Reply Quote 0
            • ferdinandF
              ferdinand
              last edited by ferdinand

              Hi,

              I am not very familiar with Cinema's token system, but I think it does not offer any kind of z-fill like (padding) functionality for the frame token.

              However, you can implement your own tokens in Python, where you could implement basically anything you want [1]. One limitation does exist also though and that is static token identifiers. You cannot implement something like "#xxx_frame, where the number of x characters signifies some kind of value without implementing a hook for each token variation (a hook for #x_frame, one for #xx_frame, one for #xxx_frame, ...).

              But you could totally implement a #frame token that returns the z-filled current frame based on the maximum number of frames in the rendering document.

              Cheers,
              zipit

              [1] https://developers.maxon.net/docs/py/2023_2/modules/c4d.plugins/index.html#c4d.plugins.RegisterToken

              MAXON SDK Specialist
              developers.maxon.net

              1 Reply Last reply Reply Quote 0
              • r_giganteR
                r_gigante @jcooper
                last edited by

                @jcooper said in How to set completely custom render output filename?:

                How do I control how much zero-padding is used for the $frame token? We typically use 4-digit, zero-padded frame tokens, but what if a situation called for, say, 6 digits?

                Hi John, with regard to the $frametoken the zero-padding is hardcoded but as stated by @zipit you can workaround it by registering your token (see here)
                .

                How do I get at the RenderData for a specific renderer such as Redshift? For instance, it has its own "filename" attribute, but I don't know how to access/modify it from the python API.

                You need to retrieve the RedShift BaseVideoPost and retrieve the corresponding data from its BaseContainer.

                Check the code below

                    # Get the active RenderData
                    renderData = doc.GetActiveRenderData()
                    if renderData is None:
                        raise RuntimeError("Failed to retrieve the render data.")
                
                    # Get the active render settings
                    renderSettings = renderData.GetData()
                    if renderSettings is None:
                        raise RuntimeError("Failed to retrieve the render settings.")
                    
                    # Get the first video post
                    videopost = renderData.GetFirstVideoPost()
                    if videopost is None:
                        raise RuntimeError("Failed to retrieve the videopost associated with the render data.")
                    
                    # Search for the RedShift videopost
                    while videopost is not None and videopost.GetType() != 1036219:
                        print "RedShift is not set as renderer in the active RenderData, check next"
                        videopost = videopost.GetNext()
                    
                    rsAOV = None
                    # Retrieve the AOV -> Filname param value
                    if videopost is not None and videopost.GetType() == 1036219: 
                        rsAOV = videopost[c4d.REDSHIFT_RENDERER_AOV_PATH]
                
                    # Reads the path stored in the render setting
                    path = renderSettings[c4d.RDATA_PATH]    
                    
                    # Add token to the path
                    path = path + rsAOV
                
                    # Tokenizes the path from the render engine
                    rpd = {'_doc': doc, '_rData': renderData, '_rBc': renderSettings, '_frame': 1}
                
                    exclude = []
                    finalFilename = c4d.modules.tokensystem.FilenameConvertTokensFilter(path, rpd, exclude)+".png"
                
                    print finalFilename
                
                1 Reply Last reply Reply Quote 0
                • First post
                  Last post