当用户保存文件时,我希望在保存之前进行检查。如果检查失败,则不会保存。我得到了这个工作与mSceneMessage和kbeforeavecheck,但我不知道如何自定义弹出消息时,它失败了。这可能吗?
import maya.OpenMaya as om
import maya.cmds as cmds
def func(retCode, clientData):
objExist = cmds.objExists('pSphere1')
om.MScriptUtil.setBool(retCode, (not objExist) ) # Cancel save if there's pSphere1 in the scene
cb_id = om.MSceneMessage.addCheckCallback(om.MSceneMessage.kBeforeSaveCheck, func)
现在显示
文件操作被用户提供的回调取消。
我回答这个问题有点慢,但我今天需要类似的东西,所以我想我应该回答。我不能决定我是否会在一般情况下推荐这一点,但严格地说,它是可以改变相当数量的静态字符串在Maya界面使用displayString
命令。简单的部分是,你知道你要找的字符串
import maya.cmds as cmds
message = u"File operation cancelled by user supplied callback."
keys = cmds.displayString("_", q=True, keys=True)
for k in keys:
value = cmds.displayString(k, q=True, value=True)
if value == message:
print("Found matching displayString: {}".format(k))
在Maya 2015上运行这个发现超过30000个注册的显示字符串并返回一个匹配的键:s_TfileIOStrings.rFileOpCancelledByUser
。我觉得很有希望。
下面是修改后的初始代码,用于更改显示字符串:
import maya.OpenMaya as om
import maya.cmds as cmds
def func(retCode, clientData):
"""Cancel save if there is a pSphere1 in the scene"""
objExist = cmds.objExists('pSphere1')
string_key = "s_TfileIOStrings.rFileOpCancelledByUser"
string_default = "File operation cancelled by user supplied callback."
string_error = "There is a pSphere1 node in your scene"
message = string_error if objExist else string_default
cmds.displayString(string_key, replace=True, value=message)
om.MScriptUtil.setBool(retCode, (not objExist))
cb_id = om.MSceneMessage.addCheckCallback(om.MSceneMessage.kBeforeSaveCheck, func)