Search code examples
python-2.7texturesnodesmayamel

Unnable to modify or query image sequence path with token <f> from file nodes


I have referenced node, which path of the texture used is an image sequence:

path\file.< f >.iff (I put it separated so that the editor doesn't change it)

When i do getAttr

texture_path = cmds.getAttr('{}.fileTextureName'.format(file_node))

I get:

path\file.0001.iff

Which is the first image of the sequence. It is not the regular sequence, but it is an animated texture, meaning sometimes it is 0001, other times 0002... etc, depending on an animation curve attached to the image Sequence.

How do I get the generic name set for the texture with the wildcard?

If I edit that attribute, Arnold Render tells me is an invalid token. Seems like there's something else happening underneath.

EDITED:

import pymel.core as pc
obj = pc.PyNode( 'textureFileNode')
obj.fileTextureName.get()

Returns the path without the wildcard also.


Solution

  • Seems like there are hidden attributes not shown in the Attribute Editor. Took me a very long time to figure all this out.

    Searching in the code executed to update the path when you activate "Use Image Sequence" checkbox, I found these three attributes:

    • fileNode.textureFileNode : This is not hidden in the UI but the contents of the field correspond to the contents of the variable if there is no image sequence on this file node. Otherwise, if you query it, it returns the first item of the sequence.
    • fileNode.fileTextureNamePattern : Contains the path shown in the Image Path field with tokens. This is the one you should query if you want the path with tokens. Can be modified.
    • fileNode.computedFileTextureNamePattern : Contains the maya generated path with tokens. It cannot be changed!

    Modifying fileTextureNamePattern will not change computedFileTextureNamePattern . To change it, you need to force Maya to regenerate it modifying fileTextureNamePattern first, then the attribute textureFileNode (in that order!).

    Important: The files should exist in order to let Maya regenerate the third parameter. Otherwise, It will not be changed and a mix of paths will be there until you update the UI by doing some change. If you are writing a batch script, it will be all mixed!

    Why is that third parameter important, why not use just the fileTextureNamePattern attribute? computedFileTextureNamePattern is used by Arnold Render, for example, to generate the ASS file. To get the pattern, the internal algorithm in maya tries to get each of them, the last, the textureFileNode. In general, if maya regenerates the third attribute, the second one is empty after that, so it's a better idea to get the generated one.