Hey,
I'm trying to attach maya geometry caches to geometry through python (and maybe that's already a mistake, could be...)
The one thing that's preventing this from working is the channel names in the cache files... (I need to do this for about 100 shapes...)
Here's the commands I'm using to attach one cache to a shape:
hs_node = pm.PyNode(maya.mel.eval('createHistorySwitch("'+shape.name()+'",false)')) cf_node = pm.PyNode(pm.cacheFile(dir=cache_path, fileName=cache_name, ia=hs_node.inp[0], attachFile=True)) pm.connectAttr(cf_node.inRange, hs_node.pfc)
(shape is a pymel shape node, cache_path and cache_name are correct, it does find those caches).
Which results in: # Error: The cache contains more than one channel. Please specify which channel using -channelName flag. #
The thing is, there's only one channel in the cache file (according to the xml file and according to MEL) and even if there were multiple ones, the documentation claims it'll just use the first one if there are multiple channels (which there aren't).
To make it all even more fun, if I specify the channel name, the command complains that that channel name does not exist. After giving me that 1 (in words: "one", as in, not multiple, not more than one) channel name.
Only thing I can think of that might be a problem is that the channel name has a ':' namespace sparator in it, could that be an issue?
I found one reference to this problem on the interweb: http://forums.cgsociety.org/showthread.php?t=1084347. With no solution though ...
Can someone explain how to get this shizophrenic, broken command to work? Or did everyone just give up on it?
Solved! Go to Solution.
Solved by BugsBunnySan. Go to Solution.
Hi,
Just curious as to exactly what you did to get this working, as I'm having issues attaching cache files.
Did you use the shape name as the channel name? And was that all it was for you?
Thanks, Owen
Hey,
here's how I got it working (can't claim this is *the* way to do it, but it works):
0.) You'll need
import pymel.core as pm import maya
1.) I have a cache_path defined, this should point to the directory that has the caches in it
cache_path = '/some/path/to/caches' # make sure this path has nice '/' slashes not the windows bs
2.) And I have a cache_name (this is the prefix of the .xml file)
cache_name = 'my_awesome_cache'
3.) Get the channel name:
channel_name = maya.mel.eval('cacheFile -dir "{cache_path}" -fileName "{cache_name}.xml" -q -channelName'.format(cache_path=cache_path, cache_name=cache_name))
This was the only way to get a working channel_name (the pymel version of this command fails the query)
4.) Also I have a shape node (as a pymel PyNode) that I want to attach the cache to (note: this has to be the actual shape, not the transform), then this works (for me):
def attach_cache(start_frame, end_frame, cache_path, cache_name, channel_name, shape): hs_node = pm.PyNode(maya.mel.eval('createHistorySwitch("'+shape.name()+'",false)')) cf_node = pm.PyNode(pm.cacheFile(dir=cache_path, fileName=cache_name, channelName=channel_name, ia=hs_node.inp[0], attachFile=True)) pm.connectAttr(cf_node.inRange, hs_node.pfc)
So first make a HistorySwitch node on the shape (using the mel command, just creating the node manually isn't a good idea), then, using pymel make a cacheFile node, connected to the historyswitch node.
so close, yet so far!
This is the code I've got which is the same as yours as far as I'm aware. Don't think I've broken anything.
def attach_cache(start_frame, end_frame, cache_path, cache_name, channel_name, shape): hs_node = pm.PyNode(maya.mel.eval('createHistorySwitch("'+shape.name()+'",false)')) cf_node = pm.PyNode(pm.cacheFile(dir=cache_path, fileName=cache_name, channelName=channel_name, ia=hs_node.inp[0], attachFile=True)) pm.connectAttr(cf_node.inRange, hs_node.pfc) channel_name = maya.mel.eval('cacheFile -dir "{cache_path}" -fileName "{cache_name}.xml" -q -channelName'.format(cache_path=dirName, cache_name=fileName)) print("Channel Name> {0}".format(channel_name)) # shape = cmds.ls(targetNode) shapeNode = pm.PyNode("nParticle1").getShape() attach_cache(0, 40, dirName, fileName, channel_name, shapeNode)
It does attach the cache, but it won't playback. I've only tried this in 2015, so I guess it could be a version issue.
It's frustrating that the attach cache menu item doesn't echo in the script editor.
One thing that might mess this up is if you already have some historyswitch nodes or something similar attached to the shape. Also check the framerange of the cache is right... Other than that I don't know...
Hello,
I was looking into this and also saw that with the attached script which creates a historyswitch node to connect to the particle doesn't actually run the cache even though it is attached.
In doing some research I found that when using the Attach Cache through the menu Maya is connecting directly to the nParticleShape node rather than into a history switch and then the nParticle. One thing you can do is, using the cacheFile command create the cache file node needed with the appropriate directory and name for the cache then append the cache using the connectAttr command to connect the appropriate attributes from the cache file to the particle shape node. The following are the three connections that I saw are made when using the attache cache through the menu:
nParticleShape1Cache1.outCacheData[0] --> nParticleShape1.positions
nParticleShape1Cache1.outCacheArrayData --> nParticleShape1.cacheArrayData
nParticleShape1Cache1.inRange --> nParticleShape1.playFromCache
Unfortunately, I have not had time to create a script for this. However, I am hoping the information I have provided is helpful in creating your own script that does it this way rather than using the switch history node.
Cheers,
So, using 2018 here, got a pretty serious load of nParticles I need to cache and I'm having the same issue. Have we gotten any closer to solving this problem? If not can you give me a little push in the right direction, is this solvable with python?