zingy zingy - 4 months ago 9x
Python Question

importing multiple cache files in Maya using Python

I am trying to write a script for importing multiple cache files for a model in Maya using Python. So far I have got the following:

import maya.cmds as cmds
cache_files_path = 'D:/Project/sfin/work/data/ram/geo'

latest_look_file = 'D:/Project/chars/ram/look/maya/ram_clean_look_v002_t005.mb'

# open the latest look file
cmds.file(latest_look_file, f = True, op = "v=0;", typ = 'mayaBinary', o = True)

cmds.select(all = True)

Now I need to start importing existing geometry cache from the 'cache_files_path' to the respective objects. Maya2013 has the mel script 'doImportCacheFile.mel' which does the task I guess. But I couldn't proceed from here.


Say the file that you have opened has a mesh named "foo_mesh", which can be checked using isinstance(pc.PyNode("foo_mesh"), pc.nt.Mesh. And there is a cache file for it named "foo_mesh_cache.xml" (consider this as the cache metadata) and "foo_mesh_data.mc"

To apply this cache to the mesh something like the following should work:

import pymel.core as pc

mesh = "foo_mesh"
xml = "foo_mesh_cache.xml"
data = "foo_mesh_data.mc"

pc.mel.doImportCacheFile(xml, "", [mesh], list())

And to find out whether a cache file has already been applied to a mesh, list it's history and see if it contains node of type pc.nt.CacheFile.