def setUp(self): self.origUndoState = cmds.undoInfo(q=1, state=1) # flush the undo queue cmds.undoInfo(state=0) cmds.undoInfo(state=1) cmds.file(new=1, f=1) # there seems to be a bug with cmds.scriptJob(listConditions=1) where # it returns none from a non-gui session import maya.api.OpenMaya as om2 if self.CONDITION in om2.MConditionMessage.getConditionNames(): cmds.condition(self.CONDITION, delete=True) om.MGlobal.executeCommand( ''' global proc int _test_UndoOrRedoAvailable_proc() { return (isTrue("UndoAvailable") || isTrue("RedoAvailable")); } ''', False, False) cmds.condition(self.CONDITION, initialize=True, d=['UndoAvailable', 'RedoAvailable'], s='_test_UndoOrRedoAvailable_proc')
def __init__(self, layout): if cmds.control("itBtn", exists=True): cmds.deleteUI("itBtn") self.layout = layout cmds.shelfLayout(layout, e=True, backgroundColor=[0.2, 0.2, 0.2], spacing=3) self.button = cmds.iconTextButton("itBtn", style="iconOnly", width=33, image=config.getPath( config.kIcon, "logo.png"), parent=layout) currentMode = cmds.setMenuMode() cmds.popupMenu(parent=self.layout, allowOptionBoxes=True) cmds.menuItem(label=u'模型', radioButton=(currentMode == "modelingMenuSet"), command=lambda *_: cmds.setMenuMode("modelingMenuSet")) cmds.menuItem(label=u'绑定', radioButton=(currentMode == "riggingMenuSet"), command=lambda *_: cmds.setMenuMode("riggingMenuSet")) cmds.menuItem(label=u'动画', radioButton=(currentMode == "animationMenuSet"), command=lambda *_: cmds.setMenuMode("animationMenuSet")) cmds.menuItem(label=u'渲染', radioButton=(currentMode == "renderingMenuSet"), command=lambda *_: cmds.setMenuMode("renderingMenuSet")) cmds.menuItem(label=u'特效', radioButton=(currentMode == "dynamicsMenuSet"), command=lambda *_: cmds.setMenuMode("dynamicsMenuSet")) cmds.menuItem(divider=True) cmds.menuItem(label=u'帮助...', command=main.UI) try: cmds.condition("ProjectChanged", delete=True) except: pass cmds.condition("ProjectChanged", state=True) cmds.scriptJob(event=["MenuModeChanged", self.__build__], parent=self.button) cmds.scriptJob(event=["NewSceneOpened", self.__refreshUI__], parent=self.button) cmds.scriptJob(event=["timeUnitChanged", self.__refreshUI__], parent=self.button) cmds.scriptJob(event=["linearUnitChanged", self.__refreshUI__], parent=self.button) cmds.scriptJob(conditionChange=["ProjectChanged", self.__refreshUI__], parent=self.button) om.MSceneMessage.addCallback(om.MSceneMessage.kBeforeSave, lambda *_: cleanUp('boundingBox')) self.__build__() self.__refreshUI__()
def setProject(cls, name): if cmds.optionVar(q="PutaoTools_Project") == name: return for project in cls.instance().data: if project["name"] == name: cmds.optionVar(sv=("PutaoTools_Project", project["name"])) cmds.condition("ProjectChanged", e=True, state=not cmds.condition( "ProjectChanged", q=True, state=True))
def setUp(self): self.origUndoState = cmds.undoInfo(q=1, state=1) # flush the undo queue cmds.undoInfo(state=0) cmds.undoInfo(state=1) cmds.file(new=1, f=1) # there seems to be a bug with cmds.scriptJob(listConditions=1) where # it returns none from a non-gui session import maya.api.OpenMaya as om2 if self.CONDITION in om2.MConditionMessage.getConditionNames(): cmds.condition(self.CONDITION, delete=True) om.MGlobal.executeCommand(''' global proc int _test_UndoOrRedoAvailable_proc() { return (isTrue("UndoAvailable") || isTrue("RedoAvailable")); } ''', False, False) cmds.condition(self.CONDITION, initialize=True, d=['UndoAvailable', 'RedoAvailable'], s='_test_UndoOrRedoAvailable_proc')
def get_state(self): return cmds.condition(self.EventType, q=True, st=True)
def tearDown(self): try: cmds.condition(self.CONDITION, delete=True) finally: if self.origUndoState != cmds.undoInfo(q=1, state=1): cmds.undoInfo(state=self.origUndoState)