我正在PySide为Maya编写项目经理。它的目的是浏览项目内容以便快速访问。所以我希望自动重新扫描新设置的项目目录。据我所知,没有像" Project Changed"在maya ScriptJob命令中。任何建议将不胜感激!
答案 0 :(得分:0)
你是对的,因为在Maya的scriptJob
命令中没有任何“Project Changed”事件,你必须有点破解这个。 以下答案意味着修改Maya的文件。因此,如果您需要在多台计算机上部署项目经理,您还必须部署对Maya文件所做的修改。
可能有一个更简单的解决方案,但无法找到如何使用现有事件有效地做到这一点。
注意:强>
我正在使用Maya 2014,因此请根据您的实际版本更改提供的路径。
解决方案1 - 基于PyMel:
C:\Program Files\Autodesk\Maya2014\Python\Lib\site-packages\pymel\core
system.py
Workspace
班级@547
中的system.py
修改chdir
函数(@621
):
@classmethod
def chdir(self, newdir):
_OpenMaya.MUserEventMessage.postUserEvent('ProjectChanged')
return cmds.workspace( dir=newdir )
打开新 Maya(需要重新启动Maya才能使修改生效)
在脚本编辑器中运行此代码:
import maya.OpenMaya as om
#Register a new event (IE: Tell maya that this event really exists)
om.MUserEventMessage.registerUserEvent('ProjectChanged')
from pymel.all import *
#This function will be called when the project will be changed
#Do your real stuff inside
def myCallbackFunction(data):
print('Got a ChangedProject event!')
#Tell Maya to run myCallbackFunction when ProjectCHanged occurs
callbackId = om.MUserEventMessage.addUserEventCallback('ProjectChanged', myCallbackFunction)
#Whange your project directory:
# - The ProjectChanged signal will be sent
# - Maya will catch it and execute myCallbackFunction
# - This will print 'Got a ChangedProject event!'
workspace.chdir(r"C:\Users\dhasselhoff\Documents\maya\projects\hookedonafeeling")
om.MUserEventMessage.removeCallback(callbackId)
解决方案2 - 基于MEL:
C:\Program Files\Autodesk\Maya2014\scripts\others
setProject.mel
修改setProject
函数(@359
):
...
// Restore the current directory. The project may have changed, but the cur dir
// need not
workspace -dir $oldCurrentDir;
python("import maya.OpenMaya as om\nom.MUserEventMessage.postUserEvent('ProjectChanged')");
}
// Try to set it directly from the name given
else
{
sp_setLocalWorkspaceWithoutPopupDialog $newProject;
python("import maya.OpenMaya as om\nom.MUserEventMessage.postUserEvent('ProjectChanged')");
}
打开新 Maya(需要重新启动Maya才能使修改生效)
在脚本编辑器中运行此代码:
import maya.OpenMaya as om
#Register a new event (IE: Tell maya that this event really exists)
om.MUserEventMessage.registerUserEvent('ProjectChanged')
#This function will be called when the project will be changed
#Do your real stuff inside
def myCallbackFunction(data):
print('Got a ChangedProject event!')
#Tell Maya to run myCallbackFunction when ProjectCHanged occurs
callbackId = om.MUserEventMessage.addUserEventCallback('ProjectChanged', myCallbackFunction)
#Whange your project directory:
# - The ProjectChanged signal will be sent
# - Maya will catch it and execute myCallbackFunction
# - This will print 'Got a ChangedProject event!'
mel.eval('setProject("C:\Users\dhasselhoff\Documents\maya\projects\hookedonafeeling");')
om.MUserEventMessage.removeCallback(callbackId)