我正在写一个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
Run Code Online (Sandbox Code Playgroud)
您可以使用ls列出所有文件节点并获取纹理路径?
allFileNodes = cmds.ls(et="file")
for eachFile in allFileNodes:
currentFile = cmds.getAttr("%s.fileTextureName" % eachFile)
Run Code Online (Sandbox Code Playgroud)
如果你想从是否选择或指定网
shapesInSel = cmds.ls(dag=1,o=1,s=1,sl=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])
Run Code Online (Sandbox Code Playgroud)
更新资料
下面是代码要与您的需求的工作
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
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2548 次 |
最近记录: |