我对这个问题有点慢,但我今天需要类似的东西,所以我想我会回应。我无法决定在一般情况下是否会推荐此方法,但严格来说,可以使用命令更改 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)