Need help importing Maya geometry cache please

Hi everyone. I’ve been trying to create a tool that would help simplify caching pipeline in our studio using geometry cache. When trying to apply the cache, if I select the mesh manually and do ‘Import Cache…’ from menu, it works. However I cannot get my script to do it. Been pulling my hairs off for a week would greatly appreciate help :frowning:

I created cache with ‘1 file per frame’ mode so the xml contains many channels along with the namespace. Here’s 2 of the channels from the XML.

  <channel12 ChannelName="exFemaleHair006:shirt_plyShape" ChannelType="FloatVectorArray" ChannelInterpretation="positions" SamplingType="Regular" SamplingRate="250" StartTime="65000" EndTime="67500"/>
    <channel13 ChannelName="exFemaleHair006:skirt_plyShape" ChannelType="FloatVectorArray" ChannelInterpretation="positions" SamplingType="Regular" SamplingRate="250" StartTime="65000" EndTime="67500"/>

Then I reference the same character with namespace cache000. I assume I need to supply the command with list matching the destination and channel name? I tried something like this but keep getting error.

geoList = [
    'cache000:shirt_ply',
    'cache000:shirt_ply'
]
cacheList = [
    'exFemaleHair006:shirt_plyShape',
    'exFemaleHair006:skirt_plyShape'
]
xml = path_to_xml_file
pc.mel.doImportCacheFile(xml, 'mcx', geoList, cacheList)

// Error: line 0: Channel exFemaleHair006:shirt_plyShape was not found. // 
// Error: line 0: Channel exFemaleHair006:skirt_plyShape was not found. // 

Can someone help point me to the right direction please? Thank you.

I use this piece of code to update cache on an object.
Hope it helps !

import maya.cmds as cmds
import pymel.core as pm
import os
import glob #to search my .xml
    
mySel = cmds.ls(sl=1)[0]
    
myCacheNode = cmds.ls(cmds.listHistory(mySel), type='cacheFile')
    
myCachePath = cmds.getAttr(myCacheNode[0] + '.cachePath') + cmds.getAttr(myCacheNode[0] + '.cacheName') + '.xml'
    
if os.path.isfile(myCachePath) and os.access(myCachePath, os.R_OK):
    pm.mel.doImportCacheFile(myCachePath, "", [mySel], list())
else:
    cmds.warning("Either no upper cache or file is not readable")

Thank you for your suggestion DW. I can’t get doImportCacheFile to work still no matter how I try.

I eventually got the cache working by generating cache separately per geometry and use pymel command cacheFile. However the warning is still there. Am I doing something wrong?

shape = 'cache000:shirt_plyshape'
switch = mel.eval('createHistorySwitch("%s",false)' % shape)
cacheNode = pc.cacheFile(f=path_to_xml, cnm=shape, ia='%s.inp[0]' % switch, attachFile=True)

// Error: Channel cache000:shirt_plyShape was not found. // 

This is what my overall code is for our cache import tool

import maya.cmds as mc
import maya.mel as mel

switch = mel.eval('createHistorySwitch("' + each + '",false);')
cacheNode = mc.cacheFile(f=(targFolder + transformNoNamespace + ".xml"), ia='%s.inp[0]' % switch , attachFile=True)
mc.connectAttr((cacheNode + ".inRange") , (switch + ".playFromCache") , force=True)

f= targFolder + transformNoNamespace + “.xml” —> is basically the path to the xml file. In my case, it’s building it with the names of scene selected geo.
each —> Shape nodes. Looping through scene selected geo with mc.ls(sl=True, dag=True, leaf=True, ni= True, long= True)

Does this work for your needs?