Hello,
I'm working on creating custom tokens and they work perfectly when I'm just rendering straight to Picture Viewer with what's actively set up in my viewport.
However, I haven't been able to figure out how to get the custom tokens to update correctly when rendering with the Takes System—whether it's multiple takes or even just one take that has different settings than the currently active take in the viewport.
Basically, my code as currently written is only able to grab the currently active settings in the document the moment I hit render, rather than applying the selected Take first and updating the custom token with the Take's settings and re-updating with each Take if there's multiple takes.
Any guidance here would be greatly appreciated. Thank you!
—
I've attached a C4D example file set up with multiple takes with different cameras and width x height output sizes to test the tokens, if you need it to understand what I'm talking about with these custom tokens when rendering straight to Picture Viewer vs. rendering multiple takes at the same time.
C4D Example File:
customTokens_takesTest.c4d
Python Script:
customTokens_takesTest.pyp
Full script below as well if you don't want to download the Python script file:
import c4d
import maxon
def GetCameraName(data):
"""
A token that looks for the active camera name and reformats the name
to be all uppercase for the filename.
Works with single render when just rendering straight to viewport with
current active settings, but does not work when rendering with
Takes that have different settings than the currently active settings.
"""
doc = c4d.documents.GetActiveDocument()
bd = doc.GetRenderBaseDraw()
sceneCam = bd.GetSceneCamera(doc)
camName = sceneCam.GetName()
return camName.upper()
def GetResolutionActive(data):
"""
A token that looks for the active rendering setting's output width
and determines whether the filename should be "highRes"or "lowRes"
based on the width.
Works with single render when just rendering straight to viewport
with current active settings, but does not work when rendering with
Takes that have different settings than the currently active settings.
"""
doc = c4d.documents.GetActiveDocument()
renderData = doc.GetActiveRenderData()
renderResX = round(renderData[c4d.RDATA_XRES])
if renderResX >= 1920:
return "activeDocHighRes"
else:
return "activeDocLowRes"
def GetResolutionTakes(data):
"""
An alternate version of the GetResolutionActive(data) above with an
attempt to use Take Data, but seems I might not be writing this correctly?
Still doesn't update correctly when rendering with Takes.
"""
doc = c4d.documents.GetActiveDocument()
takeData = doc.GetTakeData()
if takeData is None:
return
take = takeData.GetCurrentTake()
if take is None:
return
renderData = take.GetRenderData(takeData)
renderResX = round(renderData[c4d.RDATA_XRES])
c4d.EventAdd()
if renderResX >= 1920:
return "takeHighRes"
else:
return "takeLowRes"
#----------------------------------------------------------------------------------------------------------------------------------------
# Register Tokens
#----------------------------------------------------------------------------------------------------------------------------------------
if __name__=="__main__":
for registeredToken in c4d.modules.tokensystem.GetAllTokenEntries():
if registeredToken.get("_token") in ["camUppercase", "lowHighResActive", "lowHighResTakes"]:
exit()
# Filename Parsed Tokens
c4d.plugins.RegisterToken("camUppercase","[TEST] Uppercase Cam Name", "CAMNAME", GetCameraName)
c4d.plugins.RegisterToken("lowHighResActive","[TEST] Low/High Resolution [Active Doc]", "lowRes / highRes", GetResolutionActive)
c4d.plugins.RegisterToken("lowHighResTakes","[TEST] Low/High Resolution [Current Take]", "lowRes / highRes", GetResolutionTakes)