Hi,
I stumble on a problem while trying to create CacheFile objects and assign them to MeshSequenceCache modifiers with an object path.
It seems the list of object paths (.object_paths
property) is not available (empty) as soon as the CacheFile object is created, but some operations seem to trigger its evaluation.
here is my code (with paths placehodlers):
# check if CacheFile already exists (to avoid duplicates)
if 'filename.abc' not in bpy.data.cache_files:
# create the CacheFile object
bpy.ops.cachefile.open(filepath='/path/to/filename.abc')
# get the CacheFile by its name
cf = bpy.data.cache_files.get('filename.abc')
# for each selected objects
for obj in bpy.context.selected_objects:
# create or get existing MeshSequenceCache modifier
try:
msc_mod = next(mod for mod in obj.modifiers if mod.type == 'MESH_SEQUENCE_CACHE')
except:
msc_mod = obj.modifiers.new(name='MeshSequenceCache', type='MESH_SEQUENCE_CACHE')
if msc_mod is None:
# if `None`, the current selection doesn't handle MeshSequenceCache, continue...
continue
try:
# find the matching path in CacheFile.object_paths collection
abc_path = next(op for op in cf.object_paths.keys() if op == obj.name)
except:
# if none found, continue...
print('no alembic path matching {}'.format(obj.name))
continue
# if a matching path has been found, assign the CacheFile and the path to the MeshSequenceCache modifier
msc_mod.cache_file = cf
msc_mod.object_path = abc_path
But my problem is that the 1st time I execute this loop, my CacheFile object is empty, and my selected objects don’t find their matching alembic path.
The second time I execute this, magically, the CacheFile has a list of object_paths.
There seems to be something that triggers the evaluation, and the generation of “object paths”, so I guess it’s certainly possible via the API, but I didn’t found it
Do you know how I can trigger this evaluation ?
for the moment I am forced to do the operation in two steps, which is not very practical !
thanks,
Paul