def register( self ): kwargs = {} for i in range( 1 + self.has_fields ): name = [self.label, self.label + 'Options'][i] if self.has_fields: cmd_str = '%s(%d)' % ( self._perform_func_str, i ) else: cmd_str = '%s()' % ( self._perform_func_str, ) if i == self.has_fields: kwargs['annotation'] = utils.niceName( name ) else: kwargs['annotation'] = self.annotation if not pm.versions.current() >= pm.versions.v2008: kwargs['command'] = 'python("%s")' % cmd_str else: kwargs['command'] = cmd_str kwargs['commandLanguage'] = 'python' if self.category is not None: kwargs['category'] = self.category if not pm.runTimeCommand( name, exists=1 ): pm.runTimeCommand( name, default=True, **kwargs ) print "# Adding runtime:", name, ':', cmd_str
def setHotkeys(): if pm.hotkeySet('Custom', q=1, exists=1): pm.hotkeySet('Custom', edit=1, current=1) else: pm.hotkeySet('Custom', source="Maya_Default", current=1) if pm.windows.runTimeCommand(uca=1, q=1): for ca in pm.windows.runTimeCommand(uca=1, q=1): if ca.find('Custom') == -1: pm.windows.runTimeCommand(ca, edit=1, delete=1, s=1) import_command = "import PipelineTools.utilities as ul\nreload(ul)" commands_dict = {} skin_utilities_dict = {} skin_utilities_dict['BindPose'] = ( "GoToBindPose", #Command "BindPose", #Command Name ['2', True, True, False] # Key, Ctrl, Alt, Shift ) skin_utilities_dict['PaintWeight'] = ( "artAttrSkinToolScript 3", #Command "PaintWeight", #CommandName ['1', True, True, False] # Key, Ctrl, Alt, Shift ) weight_tick = 5 weight_value = 1.0 / (weight_tick - 1) for i in range(weight_tick): format_value = '%04.2f' % (weight_value * i) format_value = "".join(format_value.split('.')) skin_utilities_dict['SetWeight%s' % (format_value)] = ("\n".join([ import_command, "ul.skin_weight_setter(skin_value=%s, normalized=False)" % (weight_value * i) ]), "SetWeightTo%s" % (format_value), [ "%d" % (i + 1), False, True, False ]) commands_dict['skin_tool'] = skin_utilities_dict nameCommandList = [] for category in commands_dict: for command in commands_dict[category]: if pm.runTimeCommand(command, q=1, exists=1): pm.runTimeCommand(command, edit=1, delete=1, s=1) pm.runTimeCommand(command, category=category, command=commands_dict[category][command][0]) nameCommand = pm.nameCommand( command + "NameCommand", ann=commands_dict[category][command][1], c=command) nameCommandList.append( (nameCommand, commands_dict[category][command][2])) for nc in nameCommandList: print nc if nc[1][0]: print "hotKey is %s" % nc[1][0] pm.hotkey(keyShortcut=nc[1][0], ctl=nc[1][1], alt=nc[1][2], sht=nc[1][3], n=nc[0])
def create_or_replace_runtime_command(name, *args, **kwargs): """ A wrapper around pm.runTimeCommand that deletes the command if it already exists before running the command. """ # Delete the command if it already exists. if pm.runTimeCommand(name, exists=True): pm.runTimeCommand(name, e=True, delete=True) pm.runTimeCommand(name, *args, **kwargs)
def createRunTimeCommand(name, rCmd, ann=""): """Create run time commands from raw string. This function is used to create the mGear hotkeys. """ if pm.runTimeCommand(name, ex=True): pm.runTimeCommand(name, e=True, delete=True) pm.displayWarning("Old hotkey: " + name + " Deleted") pm.runTimeCommand(name, ann=ann, c=rCmd, cat="mGear") pm.displayInfo("Hotkey: " + name + " created")
def create_marking_menu_command(rtc, command): if pm.runTimeCommand(rtc, exists=True): pm.runTimeCommand(rtc, edit=True, delete=True) pm.runTimeCommand(rtc, category=k.MarkingMenus.category, command=k.MarkingMenus.cmd_form.format(command), commandLanguage="python") nc = pm.nameCommand(rtc + "NameCommand", annotation=rtc + 'NameCommand generated', command=rtc) return nc
def create_hotkey(command_hotkey, command=None, name=None, mel=False, maya_default=False): # prev_cmd = pm.hotkey(cmdHotkey, query=True, name=True) nice_name_hotkey = command_hotkey if pm.hotkeySet(q=True, current=True) == "Maya_Default": pm.hotkeySet("b_tools", current=True, source='Maya_Default') if not name: name = command.split(".")[-1] if maya_default: nc = name else: rtc = name nc = name + "NameCommand" if pm.runTimeCommand(rtc, exists=True): pm.runTimeCommand(rtc, edit=True, delete=True) command_language = "python" if mel: command_language = "mel" rtc = pm.runTimeCommand(rtc, annotation=name + ' Hotkey generated', category=k.Module.name, command=command, commandLanguage=command_language) nc = pm.nameCommand(nc, annotation=name + ' nameCommand generated', command=rtc) hotkey_params = dict() hotkey_params["name"] = nc if "alt" in command_hotkey.lower(): hotkey_params["altModifier"] = True command_hotkey = command_hotkey.lower().replace("alt+", "") if "ctrl" in command_hotkey.lower(): hotkey_params["ctrlModifier"] = True command_hotkey = command_hotkey.lower().replace("ctrl+", "") if "shift" in command_hotkey.lower(): hotkey_params["shiftModifier"] = True command_hotkey = command_hotkey.lower().replace("shift+", "") hotkey_params["keyShortcut"] = command_hotkey.lower() pm.hotkey(**hotkey_params) print " {} {}".format(nice_name_hotkey, rtc)
def register( self ): kwargs = {} name = self.label cmd_str = self.get_cmd_str() kwargs['annotation'] = self.annotation if not pm.versions.current() >= pm.versions.v2008: kwargs['command'] = 'python("%s")' % cmd_str else: kwargs['command'] = cmd_str kwargs['commandLanguage'] = 'python' if self.category is not None: kwargs['category'] = self.category if not pm.runTimeCommand( name, exists=1 ): pm.runTimeCommand( name, default=True, **kwargs ) print "# Adding runtime:", name, ':', cmd_str
def removeMenuHotkeys(menuName, hotkey): """ Remove all hotkeys for the given menu Args: menuName: A string name of the registered marking menu hotkey: A string representing the hotkey to use for the menu, e.g. 'Alt+Shift+Q' """ rtCmdIdFmt = "quickMenus_{0}_{1}" namedCmdIdFmt = "quickMenus_{0}_{1}_nameCmd" # get kwargs from hotkey string keyKwargs = utils.getHotkeyKwargs(hotkey) buildRtCmdId = rtCmdIdFmt.format("build", menuName) if pm.runTimeCommand(buildRtCmdId, q=True, ex=True): pm.runTimeCommand(buildRtCmdId, e=True, delete=True) destroyRtCmdId = rtCmdIdFmt.format("destroy", menuName) if pm.runTimeCommand(destroyRtCmdId, q=True, ex=True): pm.runTimeCommand(destroyRtCmdId, e=True, delete=True) # clear hotkeys if set buildNameCmdId = namedCmdIdFmt.format("build", menuName) destroyNameCmdId = namedCmdIdFmt.format("destroy", menuName) keyQueryKwargs = keyKwargs.copy() key = keyQueryKwargs.pop('k') if pm.hotkey(key, query=True, name=True, **keyQueryKwargs) == buildNameCmdId: pm.hotkey(name="", **keyKwargs) if pm.hotkey(key, query=True, releaseName=True, **keyQueryKwargs) == destroyNameCmdId: pm.hotkey(releaseName="", **keyKwargs)
def _add_menu_items(self): menu = 'MayaWindow|mainCreateMenu' # Make sure the menu is built. pm.mel.eval('ModCreateMenu "%s";' % menu) # Add to the end of the "Curve Tools" section of Create. self.add_menu_item('zMayaTools_zCreateCurve', label='Create Curve', parent='%s|createCurveTools' % menu, command=lambda unused: self.window.show(), image=pm.runTimeCommand('CVCurveTool', q=True, i=True), top_level_path='Rigging|CreateCurve')
def registerMenuHotkeys(menuName, hotkey, importCmd=None, preBuildCmd=None, secondaryCmd=None, annotation=None): """ Setup hotkeys for builds and removing marking menus on hotkey press and release. Args: menuName: A string name of the menu for which to create hotkeys hotkey: A string representing the hotkey to use for the menu, e.g. 'Alt+Shift+Q' importCmd: String formatted python for any imports required by preBuild or secondary commands preBuildCmd: String formatted python that is called before building the menu secondaryCmd: String formatted python to be called on release if the menu is not invoked annotation: A string description of the menu to use when building the runTimeCommand """ # the format for runtime command ids rtCmdIdFmt = "quickMenus_{0}_{1}" # the format for named command ids namedCmdIdFmt = "quickMenus_{0}_{1}_nameCmd" # get kwargs from hotkey string keyKwargs = utils.getHotkeyKwargs(hotkey) # shared kwargs for all runtime commands runTimeKwargs = { "annotation": annotation, "category": "Custom Scripts.quickmenus", "cl": "python", } # clean prebuild and secondary commands importCmd = importCmd if importCmd else "" preBuildCmd = preBuildCmd if preBuildCmd else "" secondaryCmd = secondaryCmd if secondaryCmd else "pass" # create run time commands buildCmd = BUILD_MENU_CMD.format(menuName=menuName, importCmd=importCmd, preBuild=preBuildCmd, secondary=secondaryCmd) destroyCmd = DESTROY_MENU_CMD.format(menuName=menuName, importCmd=importCmd, preBuild=preBuildCmd, secondary=secondaryCmd) buildRtCmdId = rtCmdIdFmt.format("build", menuName) if pm.runTimeCommand(buildRtCmdId, q=True, ex=True): pm.runTimeCommand(buildRtCmdId, e=True, delete=True) pm.runTimeCommand(buildRtCmdId, c=buildCmd, **runTimeKwargs) buildNameCmdId = namedCmdIdFmt.format("build", menuName) pm.nameCommand(buildNameCmdId, c=buildRtCmdId, ann=buildRtCmdId + " Named Command") destroyRtCmdId = rtCmdIdFmt.format("destroy", menuName) if pm.runTimeCommand(destroyRtCmdId, q=True, ex=True): pm.runTimeCommand(destroyRtCmdId, e=True, delete=True) pm.runTimeCommand(destroyRtCmdId, c=destroyCmd, **runTimeKwargs) destroyNameCmdId = namedCmdIdFmt.format("destroy", menuName) pm.nameCommand(destroyNameCmdId, c=destroyRtCmdId, ann=destroyRtCmdId + " Named Command") # make sure we're in an editable hotkey set in >2017 _switchToNonDefaultHotkeySet() pm.hotkey(name=buildNameCmdId, **keyKwargs) pm.hotkey(releaseName=destroyNameCmdId, **keyKwargs)
def setHotkeys(): """Create RuntimeCommand for Hair Ops """ if pm.hotkeySet('HairOps', q=1, exists=1): pm.hotkeySet('HairOps', edit=1, current=1) else: pm.hotkeySet('HairOps', source="Maya_Default", current=1) if pm.windows.runTimeCommand(uca=1, q=1): for ca in pm.windows.runTimeCommand(uca=1, q=1): if ca.find('HairOps') == -1: pm.windows.runTimeCommand(ca, edit=1, delete=1, s=1) importCommand = "import MeshHairTool.hairOps as ho\nreload(ho)" commandsDict = {} hairCommands_dict = {} hairCommands_dict["MakeHair"] = ("\n".join( [importCommand, "ho.makeHairMesh()"]), "Make Hair", ["", False, False, False]) hairCommands_dict['MakeHairUI'] = ("\n".join( [importCommand, "ho.makeHairUI()"]), "Make Hair UI", ["", False, False, False]) hairCommands_dict['DuplicateHair'] = ("\n".join([ importCommand, "ho.dupHairMesh()" ]), "Duplicate Hair along with Controls", ["#", False, False, False]) hairCommands_dict['MirrorHair'] = ("\n".join([ importCommand, "ho.dupHairMesh(mirror=True)" ]), "Mirror Hair along with Controls", ["%", False, False, False]) hairCommands_dict['SelectHair'] = ("\n".join([ importCommand, "ho.pickWalkHairCtrl(d='up')" ]), "Select Hair Control Root", ["3", False, True, False]) hairCommands_dict['SelectAllControls'] = ("\n".join([ importCommand, "ho.selHair(selectAll=True)" ]), "Select All Controls of Hair", ["4", False, True, False]) hairCommands_dict['SetHairPivotTip'] = ("\n".join([ importCommand, "ho.selHair(setPivot=True,pivot=-1)" ]), "set Hair Control Root Pivot to Root", ["5", False, True, False]) hairCommands_dict['SplitHairControlUp'] = ("\n".join([ importCommand, "ho.splitHairCtrl(d='up')" ]), "Add a Hair Control Toward Tip", ["2", True, True, False]) hairCommands_dict['SplitHairControlDown'] = ("\n".join([ importCommand, "ho.splitHairCtrl(d='down')" ]), "Add a Hair Control Toward Root", ["1", True, True, False]) hairCommands_dict['DeleteHairAll'] = ("\n".join([ importCommand, "ho.delHair()" ]), "Delete Hair with its controls", ["$", False, False, False]) hairCommands_dict['DeleteHairControl'] = ("\n".join([ importCommand, "ho.delHair(keepHair=True)" ]), "Delete Hair controls but keep Hair Mesh", ["", False, False, False]) hairCommands_dict['DeleteControlsUp'] = ("\n".join([ importCommand, "ho.delHair(dType='above', keepHair=True)" ]), "Delete All Controls From Select to Tip", ["4", True, True, False]) hairCommands_dict['DeleteSelectControl'] = ("\n".join([ importCommand, "ho.delHair(dType='self', keepHair=True)" ]), "Delete Select Control", ["3", True, True, False]) hairCommands_dict['DeleteControlsDown'] = ("\n".join([ importCommand, "ho.delHair(dType='below', keepHair=True)" ]), "Delete All Controls From Select to Root", ["5", True, True, False]) hairCommands_dict['RebuildControlsUp'] = ("\n".join([ importCommand, "ho.splitHairCtrl(d='up')" ]), "rebuild All Controls From Select to Tip", ["", False, False, False]) hairCommands_dict['RebuildSelectControl'] = ("\n".join([ importCommand, "ho.splitHairCtrl(d='self')" ]), "rebuild Select Control", ["", False, False, False]) hairCommands_dict['RebuildControlsDown'] = ("\n".join([ importCommand, "ho.splitHairCtrl(d='down')" ]), "rebuild All Controls From Select to Root", ["", False, False, False]) hairCommands_dict['PickWalkHideRight'] = ("\n".join([ importCommand, "ho.pickWalkHairCtrl(d='right')" ]), "Pick Walk Right and hide last Select Control", ["2", False, True, False]) hairCommands_dict['PickWalkAddRight'] = ("\n".join([ importCommand, "ho.pickWalkHairCtrl(d='right',add= True)" ]), "Pick Walk Right and add to last Select Control", ["@", False, True, False]) hairCommands_dict['PickWalkHideLeft'] = ("\n".join([ importCommand, "ho.pickWalkHairCtrl(d='left')" ]), "Pick Walk Left and hide last Select Control", ["1", False, True, False]) hairCommands_dict['PickWalkAddLeft'] = ("\n".join([ importCommand, "ho.pickWalkHairCtrl(d='left',add= True)" ]), "Pick Walk Left and add to last Select Control", ["!", False, True, False]) hairCommands_dict['HideAllHairCtrls'] = ("\n".join([ importCommand, "ho.ToggleHairCtrlVis(state='hide')" ]), "Hide All Hair Controls", ["t", False, False, True]) hairCommands_dict['ShowAllHairCtrls'] = ("\n".join([ importCommand, "ho.ToggleHairCtrlVis(state='show')" ]), "Show All Hair Controls", ["t", False, True, True]) commandsDict['HairOps'] = hairCommands_dict nameCommandList = [] for category in commandsDict: for command in commandsDict[category]: if pm.runTimeCommand(command, q=1, exists=1): pm.runTimeCommand(command, edit=1, delete=1, s=1) pm.runTimeCommand(command, category=category, command=commandsDict[category][command][0]) nameCommand = pm.nameCommand( command + "NameCommand", ann=commandsDict[category][command][1], c=command) nameCommandList.append( (nameCommand, commandsDict[category][command][2])) for nc in nameCommandList: print nc if nc[1][0]: print "hotKey is %s" % nc[1][0] pm.hotkey(keyShortcut=nc[1][0], ctl=nc[1][1], alt=nc[1][2], sht=nc[1][3], n=nc[0])