Within the blender API, how do I go about creating a CacheFile object?

Hey hey,

I’m very new to the blender API (so forgive the noob-ness) but have experience with python and the maya API.

I’m trying to write a simple batch script to attach alembic animation caches to a series of geometries using the mesh sequence cache modifier. It’s a simple for loop that needs to create the modifier then set the parameters.

Currently, i’m working through the documentation here: https://docs.blender.org/api/current/bpy.types.MeshSequenceCacheModifier.html

I need to supply a CacheFile but I have been unable to initialize an instance.

It’s mentioned here (under heading Data Creation/Removal) that new data-blocks in the bpy API can’t be created by calling the class. Instead data is added and removed via methods on the collections. The problem is I cannot find the relevant method to create a Cache file.

If anyone is across this I’d really appreciate some guidance.

Cheers

Quick tip on navigating the Blender docs - From that link, you can see that MeshSequenceCacheModifier is a “type” in Blender. And you should also be able to see that the cache_file you need to supply is of type CacheFile.

Following the link to CacheFile (https://docs.blender.org/api/current/bpy.types.CacheFile.html) you can scroll right down to the bottom and find:

References

This usually tells you the collection name you need to access to create a new one… as per the bpy.types.Mesh() and bpy.data.meshes.new(name="MyMesh") example from the quickstart guide you found.

But in this case, surprise(!) Blender sort of breaks it’s conventions and bpy.data.cache_files.new() doesn’t exist. You have to use an operator to create a new cache file:

bpy.ops.cachefile.open()

https://docs.blender.org/api/current/bpy.ops.cachefile.html

2 Likes