自定义 Maya 的 addCheckCallback 弹出消息
Customize Maya's addCheckCallback pop up message
当用户保存文件时,我希望在保存之前进行检查。如果检查失败,则不会保存。我用 mSceneMessage 和 kBeforeSaveCheck 得到了这个,但我不知道如何在失败时自定义弹出消息。这可能吗?
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)
现在显示
File operation cancelled by user supplied callback.
我回答这个问题有点慢,但我今天需要类似的东西,所以我想我会回应。我不能决定在一般情况下我是否会推荐这个,但严格来说,它 是 可以使用 displayString
命令在 Maya 界面中更改相当数量的静态字符串.简单的部分是,您知道要查找的字符串
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 个已注册的显示字符串和 returns 一个匹配键: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)
当用户保存文件时,我希望在保存之前进行检查。如果检查失败,则不会保存。我用 mSceneMessage 和 kBeforeSaveCheck 得到了这个,但我不知道如何在失败时自定义弹出消息。这可能吗?
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)
现在显示
File operation cancelled by user supplied callback.
我回答这个问题有点慢,但我今天需要类似的东西,所以我想我会回应。我不能决定在一般情况下我是否会推荐这个,但严格来说,它 是 可以使用 displayString
命令在 Maya 界面中更改相当数量的静态字符串.简单的部分是,您知道要查找的字符串
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 个已注册的显示字符串和 returns 一个匹配键: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)