I was able to figure out something that works pretty well, using the Python tag (attached to a Scene Object).
Code: Select all
import c4d
import os
import re
#
# This script is intended to be put into a Python tag assigned to a Scene
# Object. When it is evaluated, it checks the current frame number, looks at
# the paths of all the Scene's IBL paths, and rewrites any that if finds to
# have sequential names.
#
# You can change FRAMES_PER_HDRI below to control how many frames are assigned
# to a given sequential HDRI. For example, if you change it to 10, then the
# first 10 frames will use file_0000, the second 10 will use file_0001, and
# so forth.
#
# Lastly, note that because it appears the Python tag is evaluated after the
# plugin has already written the MXS, this script actually has to use frame+1
# for the value. This means that you should skip exporting the first frame of
# your animation, since it will have the wrong HDRI assigned; for example, if
# you intended to export frames 0-9, you should instead export frames 1-10.
#
FRAMES_PER_HDRI = 1
def split_name(file):
if not file:
return None, None, None, -1
name,ext = os.path.splitext(file)
m = re.search(r'[0-9]+$', name)
if not m:
return None, None, None, -1
i = m.start()
basename = name[:i]
if not basename:
return None, None, None, -1
try:
seqstr = name[i:]
seqnum = int(seqstr)
except ValueError:
return None, None, None, -1
return basename,seqstr,ext,seqnum
def main():
scene = op.GetObject()
if not scene:
print('Failed to get parent Scene.')
return
ID_MXSCENEOBJECT = 1009988
if scene.GetType() != ID_MXSCENEOBJECT:
print('Parent object is not a Scene.')
return
frame = int(doc.GetTime().GetFrame(doc.GetFps())/FRAMES_PER_HDRI)+1
if frame < 0:
print('Cannot auto-sequence for negative frames.')
return
paths = {
c4d.MX_IBE_BACKGROUND_PATH: scene[c4d.MX_IBE_BACKGROUND_PATH],
c4d.MX_IBE_ILLUMINATION_PATH: scene[c4d.MX_IBE_ILLUMINATION_PATH],
c4d.MX_IBE_REFLECTION_PATH: scene[c4d.MX_IBE_REFLECTION_PATH],
c4d.MX_IBE_REFRACTION_PATH: scene[c4d.MX_IBE_REFRACTION_PATH],
}
for key,path in paths.iteritems():
dir = os.path.dirname(path)
file = os.path.basename(path)
basename,seqstr,ext,seqnum = split_name(file)
if (not basename) or (not seqstr) or (not ext) or (seqnum == -1):
continue
newseqstr = format(frame, "0%dd" % len(seqstr))
scene[key] = os.path.join(dir, basename + newseqstr + ext)
As mentioned in the comments, you can use the FRAMES_PER_HDRI variable to use a given (sequentially-named, meaning a filename with some number of digits directly preceding the extension) HDRI for more than one frame (I recall you asked about this in your other question).
Also mentioned is that because the plugin has already written the HDRI path by the time the Python tag is evaluted, this script is purposefully assigning the wrong HDRI to the Scene Object when it is evaluated -- while exporting frame 0, the script sets the Scene Object to use HDRI 1, which is then written while exporting frame 1, and so forth.
The logic of the path replacement is just this: if any IBL path is found to have a sequential name, the sequential part of the name is replaced with a different sequential part, based on the frame number currently being exported. So, it rewrites those types of HDRI paths, but does nothing with paths that are unassigned, or assigned a non-sequential path.