Community
Maya Programming
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

cacheFile and channelNames?

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
BugsBunnySan
1507 Views, 10 Replies

cacheFile and channelNames?

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?

Tags (3)
10 REPLIES 10
Message 2 of 11
BugsBunnySan
in reply to: BugsBunnySan

Soooo, just in case anyone ever has this problem as well: Turns out the problem is more with the error message than the command >_< The problem is if it can't find the cache file, it will still report only that it can't find the channel name. (technicaly true, practiacly useless error message right there >_<) The confusion is furthered by the cacheFile node not showing the full path in the attribute editor, only the one based on Maya's project path, which is also silly. And the whole thing of having a path and a cache name, not just specifying the complete path in one go, that's also silly and more complicated than it needs to be. Ah well, you live, you learn, you tear your hair out ...
Message 3 of 11
owenrh
in reply to: BugsBunnySan

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

Message 4 of 11
BugsBunnySan
in reply to: owenrh

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.

 

 

Message 5 of 11
owenrh
in reply to: BugsBunnySan

Thanks for getting back to me. I'll give your approach a go. Hopefully it will work for me too.

Thanks again for the explanation.
Message 6 of 11
owenrh
in reply to: BugsBunnySan

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.

Message 7 of 11
BugsBunnySan
in reply to: owenrh

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...

Message 8 of 11
owenrh
in reply to: BugsBunnySan

Sure, thanks anyway. I've discovered (possibly late to the party here) that a lot of the Maya cache code is mel scripts under the hood, which you can find on the file system.

So I might try invoking/copying the existing attach cache script if I can't get the Python to work.
Message 9 of 11
santd
in reply to: owenrh

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,




David Santos

Message 10 of 11
owenrh
in reply to: santd

Thanks for looking into it David, appreciate your efforts.

I will investigate your suggestion further and see if I can script something. Thanks again.

Owen
Message 11 of 11
forrest.brent
in reply to: owenrh

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?

 

Capture.PNG

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report