[英]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)
現在它顯示
用戶提供的回調取消了文件操作。
我對這個問題有點遲鈍,但今天我需要類似的東西所以我想我會做出回應。 我不能決定我是否會推薦這在一般情況下,但嚴格來說,它是可以改變相當數量的使用瑪雅接口的靜態字符串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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.