0
我正在寫一個python腳本來輸出一個場景到一個簡單的,可讀的文件。從Maya 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
你第二塊代碼幾乎正是我所需要的,唯一的問題是它每次都獲得相同的紋理。我認爲我誤解了這段代碼的作用,我用我當前的代碼更新了我的問題。 –
我剛剛更新了我的答案,但如果你仔細看,你應該已經很容易:) – Achayan
我試過這種格式,但我遇到了一個問題:「警告:沒有指定的對象可以有連接。 「這是它試圖做shadingGrps –