在场景中只选择.tif文件,Maya-Python。

问题描述 投票:0回答:1

我试图创建一个小工具,在这个工具中,我选择场景中的所有文件(纹理),并对它们应用一个特定的过滤器。'.fileTextureName' 属性,存在于我的场景中,我得到了每一个.和。exr.tif 我有的。但我正试图删除 .exr 从我的列表中选择,并且只将过滤结果应用于 .tif. 我还没有找到一种方法来列出属性列表或者只选择我想要的文件类型。

这里只是脚本的开头。

import maya.cmds as cmds

allFileNodes = cmds.ls(type="file")

def attrList():
    for eachFile in allFileNodes:

        currentFile = cmds.getAttr(eachFile + '.fileTextureName')
        print currentFile


attrList()

任何帮助都是感激的!

python file attributes maya
1个回答
1
投票

如果你只是想根据文件的扩展名来过滤要操作的内容,那么你可以使用".fileTextureName "属性。.endswith 只包括tif扩展。

import maya.cmds as cmds

all_file_nodes = cmds.ls(type="file")

for each_file in all_file_nodes:
    image_path = cmds.getAttr(each_file + ".fileTextureName")  # Get the image's path the file is referencing.
    if image_path.lower().endswith(".jpg"):  # Only continue if the image ends with `tif`, we include `.lower()` in case the extension is upper case.
        print image_path  # Only tifs beyond this point, do what you want.
© www.soinside.com 2019 - 2024. All rights reserved.