5月份自动从不同目的地加载引用文件的脚本

2024-05-23 16:12:49 发布

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

嗨,一个为玛雅编写python脚本的初学者。我正在尝试编写一个脚本,该脚本自动打开一个Maya文件及其引用。通常,当父文件和引用文件位于不同的目标时,Maya无法打开正在引用的文件,并且必须浏览文件名才能打开该文件。我正试着把它自动化。当用户试图打开一个文件时,它应该打开所有的引用。到目前为止,我已经知道了,但主要的部分是我所困惑的。

import pymel.api as api

def callFunc():
    print "hello world" # just a print cmd to check

print "registering a file reference call back"
cb = api.MSceneMessage_addCallback(api.MSceneMessage.kAfterOpen, callFunc())

def callbackOff():
    api.MSceneMessage.removeCallback(cb)

所以当函数callFunc()被调用时,所有的操作都在这里发生。现在我不知道该怎么做了。


Tags: 文件用户import脚本api目标文件名def
1条回答
网友
1楼 · 发布于 2024-05-23 16:12:49

除非使用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()

有关fileDialog2file的更多选项,请查看位于http://download.autodesk.com/global/docs/maya2014/en_us/CommandsPython/index.html的Maya Python文档

相关问题 更多 >