除非有使用 pymel 的特定原因,否则我会使用常规的 Maya 命令:
import maya.cmds as cmds
import os
def openFileAndRemapRefs():
multipleFilters = "Maya Files (*.ma *.mb);;Maya ASCII (*.ma);;Maya Binary (*.mb);;All Files (*.*)"
# Choose file to open
filename = cmds.fileDialog2(fileFilter=multipleFilters, dialogStyle=2, fileMode=1)
# Open file with no reference loaded
cmds.file( filename[0], open=True, force=True );
# Dir containing the references
refDir = 'C:/References'
# A list of any references found in the scene
references = cmds.ls(type='reference')
# For each reference found in scene, load it with the path leading up to it replaced
for ref in references:
refFilepath = cmds.referenceQuery(ref, f=True)
refFilename = os.path.basename( refFilepath )
print 'Reference ' + ref + ' found at: ' + cmds.referenceQuery(ref, f=True)
cmds.file( os.path.join(refDir, refFilename), loadReference=ref, options='v=0;')
openFileAndRemapRefs()
有关 和 的更多选项fileDialog2
,file
请查看位于http://download.autodesk.com/global/docs/maya2014/en_us/CommandsPython/index.html的 Maya Python 文档