从Maya python脚本获取纹理文件名?

2024-10-01 05:04:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在编写一个python脚本,将场景输出到一个简单易读的文件中。在

我已经成功地输出了位置、旋转、缩放和网格名称,但是如何获得应用于网格的纹理的文件名呢?在

import maya.cmds as cmds
meshesWithoutShape = []
meshes = cmds.ls("mesh_*")
for mesh in meshes:
    if("Shape" not in mesh):
        meshesWithoutShape.append(mesh)

shapesInSel = cmds.ls(dag=1,o=1,s=1)
shadingGrps = cmds.listConnections(shapesInSel,type='shadingEngine')
shaders = cmds.ls(cmds.listConnections(shadingGrps),materials=1)
fileNode = cmds.listConnections('%s.color' % (shaders[0]), type='file')
currentFile = cmds.getAttr("%s.fileTextureName" % fileNode[0])

for mesh in meshesWithoutShape:
    print("\n" + mesh.rstrip('1234567890'))

    print round(cmds.getAttr("%s.translateX" % mesh), 2), round(cmds.getAttr("%s.translateY" % mesh), 2), round(cmds.getAttr("%s.translateZ" % mesh), 2)

    print cmds.getAttr("%s.rotateX" % mesh), cmds.getAttr("%s.rotateY" % mesh), cmds.getAttr("%s.rotateZ" % mesh)

    print cmds.getAttr("%s.scaleX" % mesh), cmds.getAttr("%s.scaleY" % mesh), cmds.getAttr("%s.scaleZ" % mesh)

    fileNode = cmds.listConnections('%s.color' % (shaders[0]), type='file')
    currentFile = cmds.getAttr("%s.fileTextureName" % fileNode[0])
    print currentFile

Tags: in网格typelsprintmeshcmdsround
1条回答
网友
1楼 · 发布于 2024-10-01 05:04:50

你可以用ls列出所有的文件节点并得到纹理路径?在

allFileNodes = cmds.ls(et="file")
for eachFile in allFileNodes:
    currentFile = cmds.getAttr("%s.fileTextureName" % eachFile)

如果要从选择或特定网格获取

^{pr2}$

更新

这里是你想要处理你的需求的代码

import maya.cmds as cmds
meshesWithoutShape = []
meshes = cmds.ls("mesh_*", tr = True)

for mesh in meshes:
    print("\n" + mesh.rstrip('1234567890'))

    print round(cmds.getAttr("%s.translateX" % mesh), 2), round(cmds.getAttr("%s.translateY" % mesh), 2), round(cmds.getAttr("%s.translateZ" % mesh), 2)

    print cmds.getAttr("%s.rotateX" % mesh), cmds.getAttr("%s.rotateY" % mesh), cmds.getAttr("%s.rotateZ" % mesh)

    print cmds.getAttr("%s.scaleX" % mesh), cmds.getAttr("%s.scaleY" % mesh), cmds.getAttr("%s.scaleZ" % mesh)
    shadingGrps = cmds.listConnections(mesh,type='shadingEngine')
    shaders = cmds.ls(cmds.listConnections(shadingGrps),materials=1)
    fileNode = cmds.listConnections('%s.color' % (shaders[0]), type='file')
    currentFile = cmds.getAttr("%s.fileTextureName" % fileNode[0])
    print currentFile

相关问题 更多 >