def cancel_save_maya(msg): """ Customize the canceled save window """ allowSave = fileIO.allow_save string_key = "s_TfileIOStrings.rFileOpCancelledByUser" string_default = "File operation cancelled by user supplied callback." string_error = msg message = string_error if allowSave else string_default cmds.displayString(string_key, replace=True, value=message)
def getPluginResource(pluginId, stringId): '''See getPluginResource.mel in Maya. Unfortunately there is no equivalent python version of this MEL proc so we created our own version of it here.''' # Form full id string. # Plugin string id's are prefixed with "p_". fullId = 'p_%s.%s' % (pluginId, stringId) if cmds.displayString(fullId, exists=True): dispStr = cmds.displayString(fullId, query=True, value=True) return dispStr else: msgFormat = mel.eval('uiRes("m_getPluginResource.kLookupFailed")') msg = cmds.format(msgFormat, stringArg=(pluginId, stringId)) cmds.error(msg)
def before_save(return_code, _=None): """Prevent accidental overwrite of locked scene""" # Manually override message given by default dialog # Tested with Maya 2013-2017 dialog_id = "s_TfileIOStrings.rFileOpCancelledByUser" message = ("Scene is locked, please save under a new name " "or run cmds.remove(\"lock\") to override") cmds.displayString(dialog_id, replace=True, value=message) # Returning false in C++ causes this to abort a save in-progress, # but that doesn't translate from Python. Instead, the `setBool` # is used to mimic this beahvior. # Docs: http://download.autodesk.com/us/maya/2011help/api/ # class_m_scene_message.html#a6bf4288015fa7dab2d2074c3a49f936 OpenMaya.MScriptUtil.setBool(return_code, not maya.is_locked())
def registerPluginResource(pluginId, stringId, resourceStr): '''See registerPluginResource.mel in Maya. Unfortunately there is no equivalent python version of this MEL proc so we created our own version of it here.''' fullId = 'p_%s.%s' % (pluginId, stringId) if cmds.displayString(fullId, exists=True): # Issue warning if the string is already registered. msgFormat = mel.eval('uiRes("m_registerPluginResource.kNotRegistered")') msg = cmds.format(msgFormat, stringArg=(pluginId, stringId)) cmds.warning(msg) # Replace the string's value cmds.displayString(fullId, replace=True, value=resourceStr) else: # Set the string's default value. cmds.displayString(fullId, value=resourceStr)