SOLVED How to set completely custom render output filename?

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.

Hi,

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

Hi,

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

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

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!

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/Cinema4DPythonSDK/html/modules/c4d.plugins/index.html#c4d.plugins.RegisterToken

@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