コード例 #1
0
ファイル: utilsBin.py プロジェクト: matthieuCantat/python
	def launchHotkeys(self):
		

		if( len(self.hotkeysInfo) == 0 ):
			mc.error( 'first add some hotkeys with:  addHotkey( letter , specialButton , cmd )' )
			

		for keyInfo in self.hotkeysInfo:
			runTimeCmdName = keyInfo[0] + '_' + self.customCmdBaseName
			self.runTimeCmdNames.append(runTimeCmdName)				
			nameCmdName    = runTimeCmdName  + 'NameCommand'

			specialKeys = [0,0,0]
			
			if( keyInfo[2] == 'ctrl' ):
				specialKeys = [1,0,0]
			elif( keyInfo[2] == 'alt' ):
				specialKeys = [0,1,0]			
			elif( keyInfo[2] == 'shift' ):
				specialKeys = [0,0,1]		

			melToEval = 'runTimeCommand -annotation "" -category "Custom Scripts" -hotkeyCtx "" -default false -commandLanguage "python" -command ( "{0}" ) {1} ; '.format( keyInfo[3] , runTimeCmdName )
		
			mel.eval(melToEval)					
			mc.nameCommand( nameCmdName , sourceType = 'mel' , annotation = nameCmdName , command = runTimeCmdName , default = False )					
			mc.hotkey( k= keyInfo[1] , ctl= specialKeys[0] , alt = specialKeys[1] , sht = specialKeys[2] ,  ctxClient = '' , name = nameCmdName  )
コード例 #2
0
def setquick(arg):
    keyadj = cmds.hotkey( '1', query=True, ctl=True )
    if keyadj ==False:
        cmds.nameCommand( 'filebridgemanager', annotation='filebridgemanager',command='source"O:/mocap/SJ_ToolBox/mel_source/filebridge.mel"')
        cmds.hotkey(k='1',ctl=1,name='filebridgemanager')  
    else:
        print "已经设置好快捷键!!\n",
コード例 #3
0
def hotkeys_resetAll():
    """
    Reset all hot keys on current hotkeySet
    """
    _set = validate_hotkeySet(False)
    log.warning("All hotkeys on '{0}' set reset to maya defaults".format(_set))
    mc.hotkey(fs=True)
コード例 #4
0
ファイル: __init__.py プロジェクト: mocap-ca/cleanup
def keys() :

    ''' creates some useful keyboard shortcuts (removing existing ones if they exist) '''

    kt = "import mocapCleanup.keyTools as kt;kt."
    la = "import mocapCleanup.labeler as la;la."

    cmds = [ [ "Home",       "alt", "SetCurrent1",      "Set Current 1",     "p", kt + "setCurrent('1')"    ] ,
             [ "Home",       ""   , "MoveToCurrent1",   "Move to current 1", "p", kt + "moveToCurrent('1')" ] ,
             [ "End",        "alt", "SetCurrent2",      "Set Current 2",     "p", kt + "setCurrent('2')"    ] ,
             [ "End",        ""   , "MoveToCurrent2",   "Move to current 2", "p", kt + "moveToCurrent('2')" ] ,
             [ "Page_Up",    "alt", "SetCurrent3",      "Set Current 3",     "p", kt + "setCurrent('3')"    ] ,
             [ "Page_Up",    ""   , "MoveToCurrent3",   "Move to current 3", "p", kt + "moveToCurrent('3')" ] ,
             [ "Page_Down",  "alt", "SetCurrent4",      "Set Current 4",     "p", kt + "setCurrent('4')"    ] ,
             [ "Page_Down",  ""   , "MoveToCurrent4",   "Move to current 4", "p", kt + "moveToCurrent('4')" ] ,
             [ "8",          ""   , "ExtractSelected",  "Extract Selected",  "p", kt + "extractSelected()"  ] ,
             [ "9",          ""   , "OneTwoTwo",        "One To Two",        "p", la + "onetwo()"           ] ]
             
    for keycode, modifier, name, title, lang, cmd in cmds:
           
        if lang == "p" : cmd="python(\"" + cmd + "\")"
        name = "peel" + name + "NameCommand"
        print("Setting " + keycode + " " + title + " to " + cmd)
        m.nameCommand( name, ann=title, c=cmd)
        if modifier == "alt" :
            m.hotkey(keyShortcut=keycode, altModifier=True, name=name)
        else :
            m.hotkey(keyShortcut=keycode, name=name) 
コード例 #5
0
ファイル: smoothWeights.py プロジェクト: lefan2016/glTools
def hotkeySetup():
	'''
	'''
	# ====================
	# - Runtime Commands -
	# ====================

	# Smooth Weights
	if mm.eval('runTimeCommand -q -ex rt_smoothWeights'):
		mm.eval('runTimeCommand -e -del rt_smoothWeights')
	mm.eval('runTimeCommand -annotation "" -category "User" -commandLanguage "python" -command "import glTools.tools.smoothWeights;reload(glTools.tools.smoothWeights);glTools.tools.smoothWeights.smoothWeights(mc.ls(sl=1),True,True)" rt_smoothWeights')

	# ========================
	# - Create Name Commands -
	# ========================

	smoothWtCmd = mc.nameCommand(		'smoothWeightsNameCommand',
										ann='smoothWeightsNameCommand',
										sourceType='mel',
										c='rt_smoothWeights' )

	# =============================
	# - Create Hotkey Assignments -
	# =============================

	mc.hotkey(keyShortcut='s',alt=True,name=smoothWtCmd)
コード例 #6
0
ファイル: hotkey.py プロジェクト: ewerybody/melDrop
def setHotkey(name, config, *args):
    log.info('setHotkey: name: %s' % name)
    
    if 'code' not in config:
        raise Exception('I need some code to setup a hotkey!')
        return
    if 'key' not in config:
        raise Exception('I need a KEY to setup a hotkey!')
        return

    nameCmd = config.get('nameCommand', name + '_NameCommand')
    # if there is no special category set make it 'User'
    cat = config.get('cat', 'User')
    # if there is no doc text/annotation just give it the name for now
    text = config.get('text', name)
    
    lang = config.get('lang', 'python')
    
    # create runtimeCommand, which is wisible in Hotkey Editor and contains actual code!
    runTimeCmd = createRunTimeCommand(name, config['code'], text, cat, lang)
    # create a nameCommand which is triggered by the hotkey
    nameCmd = cmds.nameCommand(nameCmd, ann=text, c=runTimeCmd, sourceType=lang)
    
    # now the actual hotkey with the keys and modifiers
    cmds.hotkey(k=config['key'], name=nameCmd,
                alt=config.get('alt', False),
                ctl=config.get('ctl', False))
コード例 #7
0
ファイル: smoothWeights.py プロジェクト: bennymuller/glTools
def hotkeySetup():
    """
    """
    # ====================
    # - Runtime Commands -
    # ====================

    # Smooth Weights
    if mel.eval('runTimeCommand -q -ex rt_smoothWeights'):
        mel.eval('runTimeCommand -e -del rt_smoothWeights')
    mel.eval(
        'runTimeCommand -annotation "" -category "User" -commandLanguage "python" -command "import glTools.tools.smoothWeights;reload(glTools.tools.smoothWeights);glTools.tools.smoothWeights.smoothWeights(cmds.ls(sl=1),True,True)" rt_smoothWeights')

    # ========================
    # - Create Name Commands -
    # ========================

    smoothWtCmd = cmds.nameCommand('smoothWeightsNameCommand',
                                 ann='smoothWeightsNameCommand',
                                 sourceType='mel',
                                 c='rt_smoothWeights')

    # =============================
    # - Create Hotkey Assignments -
    # =============================

    cmds.hotkey(keyShortcut='s', alt=True, name=smoothWtCmd)
コード例 #8
0
    def setupHotkey(self, name, sourceType='mel'):
        """Sets up the hotkey and nameCommand only. This is useful when linking to a maya runtimeCommand."""

        self.name = name
        # Make names consistant with Maya's convention
        self.commandName = name + 'NameCommand'
        self.sourceType = sourceType

        if self.release:
            cmds.hotkey(k=self.key,
                        alt=self.alt,
                        ctl=self.ctl,
                        cmd=self.cmd,
                        rn=self.commandName)
        else:
            cmds.hotkey(k=self.key,
                        alt=self.alt,
                        ctl=self.ctl,
                        cmd=self.cmd,
                        n=self.commandName)

        cmds.nameCommand(self.commandName,
                         ann=self.commandName,
                         c=self.name,
                         stp=self.sourceType)
コード例 #9
0
ファイル: MainViewMaya.py プロジェクト: iras/JADE
 def __init__ (self, graph, parent=None):
     '''constructor
     
     @param graph the model
     @param parent a parent QObject, or None for root window.
     '''
     super (MainMayaWindow, self).__init__(parent)
     QObject.__init__(self) # initiation indispensable for sending and receiving signals!
     
     # define scene and constrain its workspace
     self.scene = QGraphicsScene ()
     self.scene.setSceneRect (QRectF (-1000, -1000, 2000, 2000))
     
     self.graph_model = graph
     self.helper = utility.Helper (self, self.scene, self.graph_model)
     self.graph_view  = grv.GraphView (self.graph_model, self.helper)
     self.helper.setGraphView (self.graph_view)
     
     # wirings
     self.comm = self.graph_model.getComm ()
     self.connect (self.comm, SIGNAL ('deleteNode_MSignal(int)'), self.graph_view.removeTag)
     self.connect (self.comm, SIGNAL ('addLink_MSignal(int,int)'), self.graph_view.addWire)
     self.connect (self.comm, SIGNAL ('deleteLink_MSignal(int,int)'), self.graph_view.checkIfEmpty)
     self.connect (self.comm, SIGNAL ('addNode_MSignal(int, float, float)'), self.graph_view.addTag)
     
     self.scene.addItem (self.helper.getHarpoon ())
     
     self.hovered_tag_id = None
     
     # register a new command that takes care of deleting selected items and bind it to the key 'd'.
     cmds.nameCommand ('delSelection', ann='deleteSelectedItems', c='python (\"ClientMaya.ui.graph_view.removeSelectedItems ()\");')
     cmds.hotkey (k='d', name='delSelection')
コード例 #10
0
ファイル: Tools.py プロジェクト: DavideAlidosi/May9
 def _createHotkey(self):
     if cmds.runTimeCommand('%s_press' % self.ui_txt_name.text(), exists=True):
         if cmds.confirmDialog(m='name is not unique! replace?', b=['yes', 'no']) == 'no':
             return
         else:
             cmds.runTimeCommand('%s_press' % self.ui_txt_name.text(), delete=True, e=True)
             cmds.runTimeCommand('%s_release' % self.ui_txt_name.text(), delete=True, e=True)
     name = self.ui_txt_name.text()
     menu = self.ui_txt_menu.text()
     command = self.ui_txt_command.text()
     hotkey = self.ui_txt_hotkey.text().lower()
     if not hotkey:
         return
     ctrl = self.ui_chb_ctrl.isChecked()
     alt = self.ui_chb_alt.isChecked()
     shift = self.ui_chb_shift.isChecked()
     if self.SELECT == 1:    # select based
         press = "MMtoKey.press_selected(menu='%s', ctl=%s, alt=%s, sh=%s)" % (menu, ctrl, alt, shift)
         release = "MMtoKey.release_selected('%s', %i)" % (command, self.ui_cmb_language.currentIndex())
     else:   # preset based
         press = "MMtoKey.press_preset(ctl=%s, alt=%s, sh=%s)" % (ctrl, alt, shift)
         release = "MMtoKey.release_preset()"
     cmds.runTimeCommand('%s_press' % name, c=press, category='MMtoKey', cl='python')
     cmds.runTimeCommand('%s_release' % name, c=release, category='MMtoKey', cl='python')
     cmds.nameCommand('%s_PressNameCommand' % name, annotation='%s_press' % name, command='%s_press' % name)
     cmds.nameCommand('%s_ReleaseNameCommand' % name, annotation='%s_release' % name, command='%s_release' % name)
     try:
         cmds.hotkey(k=hotkey, name='%s_PressNameCommand' % name, releaseName='%s_ReleaseNameCommand' % name,
                     ctl=ctrl, alt=alt, sht=shift)
     except TypeError:
         cmds.hotkey(k=hotkey, name='%s_PressNameCommand' % name, releaseName='%s_ReleaseNameCommand' % name,
                     ctl=ctrl, alt=alt)
     cmds.warning('hotkey created')
コード例 #11
0
ファイル: hotkeys.py プロジェクト: jonntd/dmptools
def setHotkey(hotkey):
    """Creates a hotkey from a given hotkey dict"""

    # get hotkey dict data
    name = hotkey['name']
    key = hotkey['key']
    alt = hotkey['alt']
    ctl = hotkey['ctrl']
    release = hotkey['release']
    command = hotkey['command']
    if release:
        releaseName = name+"Release"
        releaseCommand = hotkey['releaseCommand']

    # check if this is not a separator
    if not 'separator' in command:
        #create hotkey command
        cmds.nameCommand(name, sourceType="mel", annotation=name, command=command)
        if release:
            cmds.nameCommand(releaseName, sourceType="mel", annotation=releaseName, command=releaseCommand)
        
        # set hotkey
        cmds.hotkey(k=key, alt=alt, ctl=ctl, name=name)    
        if release:
            cmds.hotkey(k=key, alt=alt, ctl=ctl, releaseName=releaseName)
コード例 #12
0
ファイル: HotkeyFactory.py プロジェクト: GuidoPollini/MuTools
def hotkeys_resetAll():
    """
    Reset all hot keys on current hotkeySet
    """
    _set = validate_hotkeySet(False)
    log.warning("All hotkeys on '{0}' set reset to maya defaults".format(_set))
    mc.hotkey(fs = True )
コード例 #13
0
def disableHotKey(key):
    #print key
    saveHotKey(key)
    for alt in range(0, 2):
        for ctl in range(0, 2):
            for cmd in range(0, 2):
                name = cmds.hotkey(key,
                                   q=True,
                                   n=True,
                                   alt=alt,
                                   ctl=ctl,
                                   cmd=cmd)
                rname = cmds.hotkey(key,
                                    q=True,
                                    rn=True,
                                    alt=alt,
                                    ctl=ctl,
                                    cmd=cmd)
                if (name != None or rname != None):
                    if not name in commandWhiteList:
                        cmds.hotkey(k=key,
                                    n=None,
                                    rn=None,
                                    alt=alt,
                                    ctl=ctl,
                                    cmd=cmd)

                        #print "disabling alt=%s ctl=%s cmd=%s %s - %s" % \
                        #                    (alt, ctl, cmd, name, rname)
                    else:
                        #print "not disabling %s" % name
                        pass
コード例 #14
0
ファイル: ml_toolbox.py プロジェクト: liudger/ml_tools
        def create(self, verbose=False):

            if not self.keys:
                return

            for i,k in enumerate(self.keys):

                name = self.name+'.'+self.functions[i]

                if verbose:
                    hotkeyPrint = '\t'
                    if self.altModifier[i]:
                        hotkeyPrint+='[Alt]+'
                    if self.ctrlModifier[i]:
                        hotkeyPrint+='[Ctrl]+'
                    hotkeyPrint = hotkeyPrint+'['+k+'] :\t'+name
                    print hotkeyPrint

                rtc = 'ml_hk_'+self.name+'_'+self.functions[i]

                nc = rtc+'_NC'

                if not mc.runTimeCommand(rtc, exists=True):
                    rtc = mc.runTimeCommand(rtc, default=True, annotation=name+' Hotkey generated by ml_toolbox', category='User', command=self.commands[i])

                nc = mc.nameCommand(nc, default=True, annotation=name+' nameCommand generated by ml_toolbox', command=rtc)

                mc.hotkey(keyShortcut=k, alt=self.altModifier[i], ctl=self.ctrlModifier[i], name=nc, releaseName='')
コード例 #15
0
 def _createHotkey(self):
     if cmds.runTimeCommand('%s_press' % self.ui_txt_name.text(),
                            exists=True):
         if cmds.confirmDialog(m='name is not unique! replace?',
                               b=['yes', 'no']) == 'no':
             return
         else:
             cmds.runTimeCommand('%s_press' % self.ui_txt_name.text(),
                                 delete=True,
                                 e=True)
             cmds.runTimeCommand('%s_release' % self.ui_txt_name.text(),
                                 delete=True,
                                 e=True)
     name = self.ui_txt_name.text()
     menu = self.ui_txt_menu.text()
     command = self.ui_txt_command.text()
     hotkey = self.ui_txt_hotkey.text().lower()
     if not hotkey:
         return
     ctrl = self.ui_chb_ctrl.isChecked()
     alt = self.ui_chb_alt.isChecked()
     shift = self.ui_chb_shift.isChecked()
     if self.SELECT == 1:  # select based
         press = "MMtoKey.press_selected(menu='%s', ctl=%s, alt=%s, sh=%s)" % (
             menu, ctrl, alt, shift)
         release = "MMtoKey.release_selected('%s', %i)" % (
             command, self.ui_cmb_language.currentIndex())
     else:  # preset based
         press = "MMtoKey.press_preset(ctl=%s, alt=%s, sh=%s)" % (ctrl, alt,
                                                                  shift)
         release = "MMtoKey.release_preset()"
     cmds.runTimeCommand('%s_press' % name,
                         c=press,
                         category='MMtoKey',
                         cl='python')
     cmds.runTimeCommand('%s_release' % name,
                         c=release,
                         category='MMtoKey',
                         cl='python')
     cmds.nameCommand('%s_PressNameCommand' % name,
                      annotation='%s_press' % name,
                      command='%s_press' % name)
     cmds.nameCommand('%s_ReleaseNameCommand' % name,
                      annotation='%s_release' % name,
                      command='%s_release' % name)
     try:
         cmds.hotkey(k=hotkey,
                     name='%s_PressNameCommand' % name,
                     releaseName='%s_ReleaseNameCommand' % name,
                     ctl=ctrl,
                     alt=alt,
                     sht=shift)
     except TypeError:
         cmds.hotkey(k=hotkey,
                     name='%s_PressNameCommand' % name,
                     releaseName='%s_ReleaseNameCommand' % name,
                     ctl=ctrl,
                     alt=alt)
     cmds.warning('hotkey created')
コード例 #16
0
ファイル: context.py プロジェクト: wangganggreat/MeshroomMaya
def initMVGCommand(name,
                   script,
                   source_type,
                   key_sequence,
                   alt=False,
                   ctl=False,
                   command=False,
                   release=False):
    # Runtime command
    exists = mel.eval("runTimeCommand -exists {name}".format(name=name))
    nameCommand = name + "NameCommand"
    if exists:
        cmd = "runTimeCommand -e -c \"{script}\" -cl {sourceType} {cmdName}".format(
            script=script, sourceType=source_type, cmdName=name)
        mel.eval(cmd)
    else:
        cmd = "runTimeCommand -c \"{script}\" -cl {sourceType} -cat \"MayaMVG\" {cmdName}".format(
            script=script, sourceType=source_type, cmdName=name)
        mel.eval(cmd)

    #Create nameCommand
    annotation = name
    cmds.nameCommand(nameCommand,
                     command=name,
                     annotation=name,
                     stp=source_type)

    #Check for hotkey in optionVar
    varString = "{0}_hotkey".format(name)
    cmd = "optionVar -exists {varString}".format(varString=varString)
    if mel.eval(cmd):
        cmd = "optionVar -q {varString}".format(varString=varString)
        keyArray = mel.eval(cmd)
        key_sequence = keyArray[0]
        alt = True if keyArray[1] == "1" else False
        ctl = True if keyArray[2] == "1" else False
        release = True if keyArray[3] == "1" else False
        command = True if keyArray[4] == "1" else False

    # Check hotkey validity
    commandName = cmds.hotkey(key_sequence,
                              q=True,
                              name=True,
                              ctl=ctl,
                              alt=alt,
                              cmd=command)
    if commandName != None and commandName != "":
        #TODO : proper warning
        print "WARNING : hotkey {hotkey} already assigned to \"{name}\". Please set your own sequence".format(
            hotkey=key_sequence, name=commandName)
        return

    # Bind nameCommands to hotkeys
    # TODO : use constructHotkeyCommand ?
    cmds.hotkey(keyShortcut=key_sequence,
                name=nameCommand,
                alt=alt,
                ctl=ctl,
                cmd=command)
コード例 #17
0
 def set_hotkeys(self, key_set, category=HOTKEY_CATEGORY, *args):
     """Set hotkeys to given key set under given category."""
     self.active = key_set
     cmds.optionVar(sv=(OPTVAR, key_set))
     for key in self.hotkey_map[key_set]:
         if not cmd_exists(key.name):
             self.create_runtime_cmd(key)
         self.create_name_cmd(key)
         cmds.hotkey(**key.key_args)
コード例 #18
0
ファイル: SundayHotkeyPy.py プロジェクト: elliottjames/jeeves
def SundayHotkeyWrapper(sourceType, name, key, down, release, alt, ctrl, cmd):
    if sourceType == 'python':
        print 'Setkey : ' + key + ' - Script : ' + down
        cmds.nameCommand(name + '_down', annotation = 'annotation_' + name, command = 'python( "' + down + '" )')
        cmds.nameCommand(name + '_release', annotation = 'annotation_' + release, command = 'python( "' + release + '" )')
        cmds.hotkey(k = key, name = name + '_down', releaseName = name + '_release', alt = alt, ctl = ctrl, cmd = cmd)
    else:
        print 'Setkey : ' + key + ' - Script : ' + down
        cmds.nameCommand(name + '_down', annotation = 'annotation_' + name, command = down)
        cmds.nameCommand(name + '_release', annotation = 'annotation_' + release, command = release)
        cmds.hotkey(k = key, name = name + '_down', releaseName = name + '_release', alt = alt, ctl = ctrl, cmd = cmd)
コード例 #19
0
def restoreAllHotKeys():
    global disabledHotKeys
    for hotkey in disabledHotKeys:
        cmds.hotkey(k=hotkey.key,
                    n=hotkey.name,
                    rn=hotkey.rname,
                    alt=hotkey.alt,
                    ctl=hotkey.ctl,
                    cmd=hotkey.cmd)
    disabledHotKeys = []

    cmds.savePrefs(hotkeys=True)
コード例 #20
0
ファイル: mayaHotKeys.py プロジェクト: alaindomissy/cadnano2
def restoreAllHotKeys():
    global disabledHotKeys
    for hotkey in disabledHotKeys:
        cmds.hotkey(
                k=hotkey.key,
                n=hotkey.name,
                rn=hotkey.rname,
                alt=hotkey.alt,
                ctl=hotkey.ctl,
                cmd=hotkey.cmd)
    disabledHotKeys = []

    cmds.savePrefs(hotkeys=True)
コード例 #21
0
def bt_checkCtrFHotkey():
    
    hotkeyExists = cmds.hotkey('f',query=1,ctl=1)
    
    if hotkeyExists == 1:
        print 'CTRL f hotkey already exists.  If you\'d like CTRL f to be associated with this tool simply delete the existing hotkey and rerun the tool to auto create.'
        
    else:
        print 'Automatically setting CTRL f as hotkey for this tool'
        cmds.nameCommand('bt_moveObjToCameraNameCommand',annotation='bt_moveObjToCameraNameCommand', command='bt_moveObjToCamera')
        runtimeCommandExists = cmds.runTimeCommand('bt_moveObjToCamera', exists=1)
        if runtimeCommandExists == 0:
            cmds.runTimeCommand('bt_moveObjToCamera', category='User', command='from bt_moveObjToCamera import *; bt_moveObjToCamera()')
        cmds.hotkey(keyShortcut='f',ctl=1,name='bt_moveObjToCameraNameCommand')
コード例 #22
0
    def update(self):
        """
        Update hotkeymaps.

        Will find new hotkey setting files, or update current ones with
        changes.
        """
        self.clean_hotkeys()
        self.hotkey_files = get_hotkey_files()
        self.parse_hotkeys()
        if self.active:
            cmds.hotkey(factorySettings=True)
            self.set_hotkeys(self.active)
        self.initUI()
コード例 #23
0
ファイル: mayaHotKeys.py プロジェクト: alaindomissy/cadnano2
def saveHotKey(key):
    global disabledHotKeys
    for alt in range(0, 2):
        for ctl in range(0, 2):
            for cmd in range(0, 2):
                name = cmds.hotkey(
                                key, query=True, name=True,
                                alt=alt, ctl=ctl, cmd=cmd)
                rname = cmds.hotkey(
                                key, query=True, releaseName=True,
                                alt=alt, ctl=ctl, cmd=cmd)
                if (name != None or rname != None):
                    disabledHotKeys.append(
                                HotKey(key, name, rname, alt, ctl, cmd))
コード例 #24
0
ファイル: copyPasteWeights.py プロジェクト: auqeyjf/glTools
def hotkeySetup():
	'''
	'''
	# ====================
	# - Runtime Commands -
	# ====================
	
	# Copy Weights
	if mm.eval('runTimeCommand -q -ex rt_copyWeights'):
		mm.eval('runTimeCommand -e -del rt_copyWeights')
	mm.eval('runTimeCommand -annotation "" -category "User" -commandLanguage "python" -command "import glTools.tools.copyPasteWeights;reload(glTools.tools.copyPasteWeights);glTools.tools.copyPasteWeights.copyWeights()" rt_copyWeights')
	
	# Paste Weights
	if mm.eval('runTimeCommand -q -ex rt_pasteWeights'):
		mm.eval('runTimeCommand -e -del rt_pasteWeights')
	mm.eval('runTimeCommand -annotation "" -category "User" -commandLanguage "python" -command "import glTools.tools.copyPasteWeights;reload(glTools.tools.copyPasteWeights);glTools.tools.copyPasteWeights.pasteWeights()" rt_pasteWeights')
	
	# Average Weights
	if mm.eval('runTimeCommand -q -ex rt_averageWeights'):
		mm.eval('runTimeCommand -e -del rt_averageWeights')
	mm.eval('runTimeCommand -annotation "" -category "User" -commandLanguage "python" -command "import glTools.tools.copyPasteWeights;reload(glTools.tools.copyPasteWeights);glTools.tools.copyPasteWeights.averageWeights()" rt_averageWeights')
	
	# Auto Average Weights
	if mm.eval('runTimeCommand -q -ex rt_autoAverageWeights'):
		mm.eval('runTimeCommand -e -del rt_autoAverageWeights')
	mm.eval('runTimeCommand -annotation "" -category "User" -commandLanguage "python" -command "import glTools.tools.copyPasteWeights;reload(glTools.tools.copyPasteWeights);glTools.tools.copyPasteWeights.autoAverageWeights()" rt_autoAverageWeights')
	
	# ========================
	# - Create Name Commands -
	# ========================
	
	copyWtCmd = mc.nameCommand(		'copyWeightsNameCommand',
									ann='copyWeightsNameCommand',
									sourceType='mel',
									c='rt_copyWeights' )
	
	pasteWtCmd = mc.nameCommand(	'pasteWeightsNameCommand',
									ann='pasteWeightsNameCommand',
									sourceType='mel',
									c='rt_pasteWeights' )
	
	averageWtCmd = mc.nameCommand(	'averageWeightsNameCommand',
									ann='averageWeightsNameCommand',
									sourceType='mel',
									c='rt_averageWeights' )
	
	autoAverageWtCmd = mc.nameCommand(	'autoAverageWeightsNameCommand',
										ann='autoAverageWeightsNameCommand',
										sourceType='mel',
										c='rt_autoAverageWeights' )
	
	# =============================
	# - Create Hotkey Assignments -
	# =============================
	
	mc.hotkey(keyShortcut='c',alt=True,name=copyWtCmd)
	mc.hotkey(keyShortcut='v',alt=True,name=pasteWtCmd)
	mc.hotkey(keyShortcut='x',alt=True,name=averageWtCmd)
	mc.hotkey(keyShortcut='a',alt=True,name=autoAverageWtCmd)
コード例 #25
0
ファイル: util.py プロジェクト: gfixler/tomayto
def createTomaytoKeymap(callbackName="tomaytoCB",
                        nameCommandPrefix="tomayto",
                        **kwargs):
    """
    Creates Maya nameCommands and hotkeys for the cartesian product of all
    keys, modifiers, and press and release states, pointing them all toward
    a default, global handler. This pointing is done to a default name in
    the global space, as nameCommands are MEL-only, and, as such, are
    difficult (but not impossible) to point to existing Python identifiers.
    This means that a callable of that name must be created in the global space
    to handle the information from the nameCommands.
    """
    for key in allKeys:
        for a in [False, True]:
            for c in [False, True]:
                modTag = ("_alt" if a else "") + ("_ctrl" if c else "")
                nameCommandName = nameCommandPrefix + (modTag if modTag else
                                                       "") + "_" + keyName(key)

                # Over-escaping required when callback commands are created by mel python calls
                if key == '"':
                    key = '\\\\\\\"'
                if key == '\\':
                    key = '\\\\\\\\'

                # press nameCommand
                callback = "python(\"" + callbackName + "(\\\"" + key + "\\\", " + str(
                    a) + ", " + str(c) + ", True)\")"
                cmds.nameCommand(nameCommandName + "_press",
                                 annotation=nameCommandName + "_press",
                                 command=callback)
                print "created", nameCommandName + "_press nameCommand"

                # release nameCommand
                callback = "python(\"" + callbackName + "(\\\"" + key + "\\\", " + str(
                    a) + ", " + str(c) + ", False)\")"
                cmds.nameCommand(nameCommandName + "_release",
                                 annotation=nameCommandName + "_release",
                                 command=callback)
                print "created", nameCommandName + "_release nameCommand"

                # hotkey for both press and release nameCommands for current key + mods
                cmds.hotkey(keyShortcut=key,
                            name=nameCommandName + "_press",
                            releaseName=nameCommandName + "_release",
                            altModifier=a,
                            ctrlModifier=c)
                print "created", nameCommandName, " press/release hotkey"
コード例 #26
0
 def hotkeyCheck(self, key, ctl, alt):
     if key != "":
         q = cmds.hotkey(key, query=True, alt=alt, ctl=ctl, name=True)
         if q != None and "NameCom" in q: q = q[7:]
         return q
     else:
         return ""
コード例 #27
0
ファイル: generalToolsUI.py プロジェクト: Italic-/maya-prefs
 def hotkeyCheck(self, key, ctl, alt):
     if key != "":
         q = cmds.hotkey(key, query=True, alt=alt, ctl=ctl, name=True)
         if q != None and "NameCom" in q: q = q[7:]
         return q
     else:
         return ""
コード例 #28
0
def load():
    '''loads animation environment'''
    print "loading animation environment presets..."
    #set autoKey
    cmds.autoKeyframe( state=True )
    #set 24fps and playback on all viewports
    cmds.playbackOptions(ps=1.0, v='all')
    #set unlimited undo's
    cmds.undoInfo( state=True, infinity=True )
    #set manipulator sizes
    if lib.checkAboveVersion(2014):
        cmds.manipOptions( r=False, hs=55, ls=4, sph=1 )
    else:
        cmds.manipOptions( r=False, hs=55, ls=4 )
    #set framerate visibility
    mel.eval("setFrameRateVisibility(1);")
    #gimbal rotation
    cmds.manipRotateContext('Rotate', e=True, mode=2)
    #world translation
    cmds.manipMoveContext('Move', e=True, mode=2)
    #time slider height
    aPlayBackSliderPython = mel.eval('$tmpVar=$gPlayBackSlider')
    cmds.timeControl(aPlayBackSliderPython, h=45, e=True);
    #special tick color
    cmds.displayRGBColor("timeSliderTickDrawSpecial", 1,0.5,0)

    #check if hotkeys have been set
    if (cmds.hotkey( 't', ctl=True, query=True, name = True)== 'CharacterAnimationEditorNameCommand'):
        print "Hotkeys have been previously loaded"
    else:
        setHotkeys('default')

    print "ENVIRONMENT SET\n", #the comma forces output on the status line
コード例 #29
0
def _register_hotkey():
    script_path = os.path.dirname(__file__) + "/scripts"

    command = """
# -------------------------
# MayaWindowSwitcher
# Author: @tm8r
# https://github.com/tm8r/MayaWindowSwitcher
# -------------------------

import os
import sys

from maya import cmds

def switch_window():
    script_path = "{0}"
    if not os.path.exists(script_path):
        cmds.error("WindowSwitcher install directory is not found. path={0}")
        return
    if script_path not in sys.path:
        sys.path.insert(0, script_path)

    import window_switcher.view
    window_switcher.view.WindowSwitcher.switch()

switch_window()""".format(script_path)

    command_name = "WindowSwitcher"
    if cmds.runTimeCommand(command_name, ex=True):
        cmds.runTimeCommand(command_name, e=True, delete=True)
    cmds.runTimeCommand(command_name,
                        ann="Open WindowSwitcher",
                        category="User",
                        command=command,
                        commandLanguage="python")
    named_command = command_name + "Command"
    named_command = cmds.nameCommand(
        named_command,
        annotation="Open WindowSwitcher",
        command=command_name,
    )
    if int(cmds.about(v=True)) <= 2015:
        cmds.hotkey(k="T", ctl=True, n=named_command)
        return

    cmds.hotkey(k="t", ctl=True, sht=True, n=named_command)
コード例 #30
0
ファイル: userHotkeys.py プロジェクト: cpenv/maya_module
def hotkey(name, key_sequence, script, source_type="python",
           release_name="", release_script=None, annotation=None):
    '''A more convenient function for defining maya hotkeys.'''

    #Create nameCommands
    if not annotation:
        annotation = name

    runtime_cmd(name, script, source_type)
    cmds.nameCommand(
        name,
        command=name,
        annotation=annotation,
        stp=source_type)
    if release_script and release_name:
        runtime_cmd(release_name, release_script, source_type)
        cmds.nameCommand(
            release_name,
            command=release_name,
            annotation=annotation,
            stp=source_type)

    #Bind nameCommands to hotkeys
    ctrl = False
    alt = False
    ctrl_match = re.search(r"[Cc]trl\+", key_sequence)
    alt_match = re.search(r"[Aa]lt\+", key_sequence)
    if ctrl_match:
        ctrl = True
        key_sequence = key_sequence.replace(ctrl_match.group(), "")
    if alt_match:
        alt = True
        key_sequence = key_sequence.replace(ctrl_match.group(), "")

    if not release_name:
        cmds.hotkey(
            keyShortcut=key_sequence,
            name=name,
            alt=alt,
            ctl=ctrl)
    else:
        cmds.hotkey(
            keyShortcut=key_sequence,
            name=name,
            alt=alt,
            ctl=ctrl,
            releaseName=release_name)
コード例 #31
0
ファイル: HotkeyMaker.py プロジェクト: DavideAlidosi/May9
    def _hotkey(self):
        """create hotkey"""
        name = self.ui.line_name.text()
        if cmds.runTimeCommand('%s_press' % name, exists=True):
            if cmds.confirmDialog(m='name is not unique! replace?', b=['yes', 'no']) == 'no':
                return
            else:
                cmds.runTimeCommand('%s_press' % name, delete=True, e=True)
                cmds.runTimeCommand('%s_release' % name, delete=True, e=True)
        hotkey = self.ui.line_hotkey.text().lower()
        if not hotkey:
            return

        # build menu
        ctrl = self.ui.chb_ctrl.isChecked()
        alt = self.ui.chb_alt.isChecked()
        shift = self.ui.chb_shift.isChecked()
        if self.COMMANDS[self.ui.cmb_method.currentIndex()][0] == "custom":
            press = "MMtoKey.pressCustom(ctl=%s, alt=%s, sh=%s, menu_type=%i, menu_name='%s')"
            press %= ctrl, alt, shift, self.ui.cmb_menu.currentIndex(), self.ui.line_menu.text()
        elif self.COMMANDS[self.ui.cmb_method.currentIndex()][0] == "selected":
            press = "MMtoKey.pressSelected(ctl=%s, alt=%s, sh=%s)" % (ctrl, alt, shift)
        else:
            press = "MMtoKey.pressPreset(ctl=%s, alt=%s, sh=%s)" % (ctrl, alt, shift)

        # release command
        if self.COMMANDS[self.ui.cmb_method.currentIndex()][1] == "custom":
            release = "MMtoKey.releaseCustom(command_always=%s, command='%s', language=%i)"
            release %= (self.ui.cmb_menu.currentIndex(), self.ui.line_command.text().replace("'", "\\'"),
                        self.ui.cmb_command.currentIndex())
        elif self.COMMANDS[self.ui.cmb_method.currentIndex()][1] == "selected":
            release = "MMtoKey.releaseSelected()"
        else:
            release = "MMtoKey.releasePreset()"

        # create runtime and name commands
        cmds.runTimeCommand('%s_press' % name, c=press, category='MMtoKey', cl='python')
        cmds.runTimeCommand('%s_release' % name, c=release, category='MMtoKey', cl='python')
        cmds.nameCommand('%s_PressNameCommand' % name, annotation='%s_press' % name, command='%s_press' % name)
        cmds.nameCommand('%s_ReleaseNameCommand' % name, annotation='%s_release' % name, command='%s_release' % name)
        try:
            cmds.hotkey(k=hotkey, name='%s_PressNameCommand' % name, releaseName='%s_ReleaseNameCommand' % name,
                        ctl=ctrl, alt=alt, sht=shift)
        except TypeError:
            cmds.hotkey(k=hotkey, name='%s_PressNameCommand' % name, releaseName='%s_ReleaseNameCommand' % name,
                        ctl=ctrl, alt=alt)
        cmds.warning('hotkey created')
コード例 #32
0
    def setHotkey(self, hotkeyDict):
        message = "Are you sure?\n\n"

        #format message
        for loopIndex, loopCommand in enumerate(hotkeyDict):

            command = loopCommand["command"]
            name = loopCommand["name"]
            key = loopCommand["hotkey"]
            alt = loopCommand["alt"]
            ctl = loopCommand["ctl"]
            q = cmds.text("query%s" % name, query=True, label=True)

            commandKeys = ""
            if ctl: commandKeys += "Ctl + "
            if alt: commandKeys += "Alt + "

            message += "%s (%s%s)" % (name, commandKeys, key)
            if q != "": message += " is assigned to: %s" % q
            message += "\n"

        confirm = cmds.confirmDialog(title='Confirm',
                                     message=message,
                                     button=['Yes', 'No'],
                                     defaultButton='Yes',
                                     cancelButton='No',
                                     dismissString='No')

        if confirm == 'Yes':
            for loopIndex, loopCommand in enumerate(hotkeyDict):

                command = loopCommand["command"]
                name = loopCommand["name"]
                key = loopCommand["hotkey"]
                alt = loopCommand["alt"]
                ctl = loopCommand["ctl"]

                cmds.nameCommand(name,
                                 command='python("%s");' % command,
                                 annotation=name)
                cmds.hotkey(k=key, alt=alt, ctl=ctl, name=name)

                aToolsMod.saveInfoWithUser("hotkeys", name, [key, alt, ctl])
                self.updateHotkeyCheck(name)

            cmds.savePrefs(hotkeys=True)
コード例 #33
0
    def set_hotkey(self, name, mode, sequence, open_cmd, close_cmd,
                   switch_cmd):
        from maya import cmds, mel

        current_hotkey_set = cmds.hotkeySet(current=True, query=True)
        if current_hotkey_set == 'Maya_Default':
            msg = 'The current hotkey set is locked, change in the hotkey editor'
            warning('Hotbox designer', msg)
            return mel.eval('hotkeyEditorWindow;')

        use_alt = 'Alt' in sequence
        use_ctrl = 'Ctrl' in sequence
        use_shift = 'Shift' in sequence
        touch = sequence.split('+')[-1]
        show_name = 'showHotbox_{n}'.format(n=name)
        hide_name = 'hideHotbox_{n}'.format(n=name)
        switch_name = 'switchHotbox_{n}'.format(n=name)

        if mode == SETMODE_PRESS_RELEASE:
            cmds.nameCommand(show_name,
                             annotation='show {n} hotbox'.format(n=name),
                             command=format_command_for_mel(open_cmd),
                             sourceType='python')

            cmds.nameCommand(hide_name,
                             annotation='hide {n} hotbox'.format(n=name),
                             command=format_command_for_mel(close_cmd),
                             sourceType='python')

            cmds.hotkey(keyShortcut=touch,
                        altModifier=use_alt,
                        ctrlModifier=use_ctrl,
                        shiftModifier=use_shift,
                        name=show_name,
                        releaseName=hide_name)
        else:
            cmds.nameCommand(switch_name,
                             annotation='switch {n} hotbox'.format(n=name),
                             command=format_command_for_mel(switch_cmd),
                             sourceType='python')

            cmds.hotkey(keyShortcut=touch,
                        altModifier=use_alt,
                        ctrlModifier=use_ctrl,
                        shiftModifier=use_shift,
                        name=switch_name)
コード例 #34
0
ファイル: context.py プロジェクト: jonntd/mayaMVG
def initMVGCommand(name, script, source_type, key_sequence, alt=False, ctl=False, command=False, release=False):
    # Runtime command
    exists = mel.eval("runTimeCommand -exists {name}".format(name=name))
    nameCommand = name + "NameCommand"
    if exists:
        cmd = "runTimeCommand -e -c \"{script}\" -cl {sourceType} {cmdName}".format(script=script, sourceType=source_type, cmdName=name)
        mel.eval(cmd)
    else:
        cmd = "runTimeCommand -c \"{script}\" -cl {sourceType} -cat \"MayaMVG\" {cmdName}".format(script=script, sourceType=source_type, cmdName=name)
        mel.eval(cmd)

    #Create nameCommand
    annotation = name
    cmds.nameCommand(
        nameCommand,
        command=name,
        annotation=name,
        stp=source_type)

    #Check for hotkey in optionVar
    varString = "{0}_hotkey".format(name)
    cmd = "optionVar -exists {varString}".format(varString=varString);
    if mel.eval(cmd):
        cmd = "optionVar -q {varString}".format(varString=varString)
        keyArray = mel.eval(cmd)
        key_sequence = keyArray[0]
        alt = True if keyArray[1] == "1" else False
        ctl = True if keyArray[2] == "1" else False
        release = True if keyArray[3] == "1" else False
        command = True if keyArray[4] == "1" else False
        
    # Check hotkey validity
    commandName = cmds.hotkey(key_sequence, q=True, name=True, ctl=ctl, alt=alt, cmd=command)
    if commandName != None and commandName != "":
        #TODO : proper warning
        print "WARNING : hotkey {hotkey} already assigned to \"{name}\". Please set your own sequence".format(hotkey=key_sequence, name=commandName);
        return
    
    # Bind nameCommands to hotkeys
    # TODO : use constructHotkeyCommand ? 
    cmds.hotkey(
      keyShortcut=key_sequence,
      name=nameCommand,
      alt=alt,
      ctl=ctl,
      cmd=command)
コード例 #35
0
ファイル: hotkey.py プロジェクト: willhoag/AnimTools
    def setupHotkey(self, name, sourceType='mel'):
        """Sets up the hotkey and nameCommand only. This is useful when linking to a maya runtimeCommand."""

        self.name = name
        # Make names consistant with Maya's convention
        self.commandName = name + 'NameCommand'
        self.sourceType = sourceType

        if self.release:
            cmds.hotkey(k=self.key, alt=self.alt,
                        ctl=self.ctl, cmd=self.cmd, rn=self.commandName)
        else:
            cmds.hotkey(k=self.key, alt=self.alt,
                        ctl=self.ctl, cmd=self.cmd, n=self.commandName)

        cmds.nameCommand(
            self.commandName, ann=self.commandName, c=self.name, stp=self.sourceType)
コード例 #36
0
def setUnsetContextHotkeys():
    """
	Sets / unsets context hotkeys.
	"""

    sequence = TRANSFERT_SELECTION_HOTKEY
    command = "python(\"import snippets.libraries.others as others; reload(others); others.transfertSelectionToUserTarget()\")"
    name = "transfertSelectionNamedCommand"
    if cmds.hotkey(sequence, query=True, name=True) != name:
        print("%s | Assigning '%s' hotkey to '%s' command!" %
              (__name__, sequence, name))
        DEFAULTS_HOTKEYS[sequence] = {
            "name": cmds.hotkey(sequence, query=True, name=True),
            "releaseName": cmds.hotkey(sequence, query=True, releaseName=True)
        }

        cmds.nameCommand(name,
                         annotation="Transfert Selection",
                         command=command)
        cmds.hotkey(k=sequence, rcr=True, name=name)
    else:
        hotkey = DEFAULTS_HOTKEYS.get(sequence)
        if hotkey:
            print("%s | Unassigning '%s' hotkey from '%s' command!" %
                  (__name__, sequence, name))
            cmds.hotkey(k=sequence,
                        name=hotkey.get("name"),
                        releaseName=hotkey.get("releaseName"))
    return True
コード例 #37
0
def runtimeCommand():
    if not cmds.runTimeCommand('switchRTC', exists = True):
        cmds.runTimeCommand('switchRTC',
                            default = True,
                            category = 'User',
                            ann = "switches wieght unlocked influences",
                            c = 'switchInfluence()')
    
    cmds.nameCommand('switchNC',
                     ann = "Create a Sphere",
                     default = True,
                     command = 'switchRTC')
    if version >= 2016:
        clHotkeySet = "slHotKeySet"
        if not cmds.hotkeySet (clHotkeySet, exists = True):
            cmds.hotkeySet(clHotkeySet, source = 'Maya_Default', current = True)
        else:
            cmds.hotkeySet (clHotkeySet, e = True, current = True)
    cmds.hotkey(k = ';', n = 'switchNC')
コード例 #38
0
    def setup_hotKey(self):
        self.validate_hotkeySet()

        _press = ''
        if self._valid_cmdPress:
            #_press = mc.nameCommand( self._valid_cmdPress + 'COMMAND', annotation=self._valid_cmdPress, command=self._valid_cmdPress)
            _press = self._valid_cmdPress

        _release = ''
        if self._valid_cmdRelease:
            #_release = mc.nameCommand( self._valid_cmdRelease + 'COMMAND', annotation=self._valid_cmdRelease, command=self._valid_cmdRelease)
            _release = self._valid_cmdRelease

        _d = {
            'keyShortcut': self._d_fromUI.get('hotkey', self._d_kws['hotkey']),
            'name': _press,
            'releaseName': _release,
            'altModifier': False,
            'ctrlModifier': False,
            'shiftModifier': False
        }
        _l_order = ['keyShortcut']
        _modifer = self.validateModifier()

        if _modifer and _modifer + 'Modifier' in _d.keys():
            _d[_modifer + 'Modifier'] = True

        if mayaVersion < 2016:
            _d.pop('shiftModifier')
            if _modifer == 'shift':
                log.error(
                    "The shiftModifer was added in Maya 2016. Cannot setup.")
                return
        cgmGeneral.log_info_dict(_d, 'hotkey args')

        _k = _d.get('keyShortcut')

        log.info(_k)
        log.info(_d)
        mc.hotkey(_k, **_d)  #...run it
        mc.savePrefs(
            hk=True)  #...have to save prefs after setup or it won't keep
コード例 #39
0
def saveHotKey(key):
    global disabledHotKeys
    for alt in range(0, 2):
        for ctl in range(0, 2):
            for cmd in range(0, 2):
                name = cmds.hotkey(key,
                                   query=True,
                                   name=True,
                                   alt=alt,
                                   ctl=ctl,
                                   cmd=cmd)
                rname = cmds.hotkey(key,
                                    query=True,
                                    releaseName=True,
                                    alt=alt,
                                    ctl=ctl,
                                    cmd=cmd)
                if (name != None or rname != None):
                    disabledHotKeys.append(
                        HotKey(key, name, rname, alt, ctl, cmd))
コード例 #40
0
def registerHotkey():
    """
    Register hotkey to set focus to the search field, the hotkey combination
    registered is Ctrl + Alt + Space. If a hotkey is already registered to
    that combination a failed message will be printed.
    """
    hk = "rjCMDSearchHK"
    cmd = 'python("import {0}; {0}.focus()")'.format(__name__)
    registered = cmds.hotkey("Space", alt=1, ctl=1, query=1, name=1)

    # check if a hotkey is already registered to the key combination
    if registered and registered != hk:
        print "Search Commands: installation failed ( Hotkey )"
        return

    # register hotkey
    cmds.nameCommand(hk, annotation="Ctrl + Alt + Space", command=cmd)
    cmds.hotkey(k="Space", alt=1, ctl=1, name=hk)

    print "Search Commands: installation succeeded ( Hotkey )"
コード例 #41
0
ファイル: ml_toolbox.py プロジェクト: sod4602/ml_tools
        def create(self, verbose=False):

            if not self.keys:
                return

            for i, k in enumerate(self.keys):

                name = self.name + '.' + self.functions[i]

                if verbose:
                    hotkeyPrint = '\t'
                    if self.altModifier[i]:
                        hotkeyPrint += '[Alt]+'
                    if self.ctrlModifier[i]:
                        hotkeyPrint += '[Ctrl]+'
                    hotkeyPrint = hotkeyPrint + '[' + k + '] :\t' + name
                    print hotkeyPrint

                rtc = 'ml_hk_' + self.name + '_' + self.functions[i]

                nc = rtc + '_NC'

                if not mc.runTimeCommand(rtc, exists=True):
                    rtc = mc.runTimeCommand(rtc,
                                            default=True,
                                            annotation=name +
                                            ' Hotkey generated by ml_toolbox',
                                            category='User',
                                            command=self.commands[i])

                nc = mc.nameCommand(nc,
                                    default=True,
                                    annotation=name +
                                    ' nameCommand generated by ml_toolbox',
                                    command=rtc)

                mc.hotkey(keyShortcut=k,
                          alt=self.altModifier[i],
                          ctl=self.ctrlModifier[i],
                          name=nc,
                          releaseName='')
コード例 #42
0
ファイル: mayaHotKeys.py プロジェクト: alaindomissy/cadnano2
def disableHotKey(key):
    #print key
    saveHotKey(key)
    for alt in range(0, 2):
        for ctl in range(0, 2):
            for cmd in range(0, 2):
                name = cmds.hotkey(
                                key, q=True, n=True,
                                alt=alt, ctl=ctl, cmd=cmd)
                rname = cmds.hotkey(
                                key, q=True, rn=True,
                                alt=alt, ctl=ctl, cmd=cmd)
                if (name != None or rname != None):
                    if not name in commandWhiteList:
                        cmds.hotkey(k=key, n=None, rn=None,
                                    alt=alt, ctl=ctl, cmd=cmd)

                        #print "disabling alt=%s ctl=%s cmd=%s %s - %s" % \
                        #                    (alt, ctl, cmd, name, rname)
                    else:
                        #print "not disabling %s" % name
                        pass
コード例 #43
0
ファイル: __init__.py プロジェクト: jonntd/personal-cg
def assignDefaultHotkey(cmd_name, cmd_string, cmd_annotation, cmd_hotkey):
    exists = cmds.runTimeCommand(cmd_name, exists=True)
    if exists:
        cmds.runTimeCommand(cmd_name, edit=True, delete=True)

    runtime = cmds.runTimeCommand(cmd_name,
                                  command=cmd_string,
                                  category='User',
                                  annotation=cmd_annotation)
    if not exists:
        command = cmds.nameCommand(command=runtime,
                                   sourceType='python',
                                   annotation=cmd_annotation)
        cmds.hotkey(altModifier=True,
                    keyShortcut=cmd_hotkey,
                    releaseName=command,
                    releaseCommandRepeat=True)

        cmds.evalDeferred(
            Callback(log, 'Assigned default hotkey (ALT+%s) for command: %s.',
                     cmd_hotkey, cmd_name))
    return
コード例 #44
0
ファイル: generalToolsUI.py プロジェクト: Italic-/maya-prefs
 def setHotkey(self, hotkeyDict):
     message = "Are you sure?\n\n"    
     
     #format message
     for loopIndex, loopCommand in enumerate(hotkeyDict):
             
         command = loopCommand["command"]
         name    = loopCommand["name"]
         key     = loopCommand["hotkey"]
         alt     = loopCommand["alt"]
         ctl     = loopCommand["ctl"]
         q       = cmds.text("query%s"%name, query=True, label=True)
         
         commandKeys = ""
         if ctl: commandKeys += "Ctl + "
         if alt: commandKeys += "Alt + "
         
         message += "%s (%s%s)"%(name, commandKeys, key)
         if q != "": message += " is assigned to: %s"%q
         message += "\n"
         
     confirm = cmds.confirmDialog( title='Confirm', message=message, button=['Yes','No'], defaultButton='Yes', cancelButton='No', dismissString='No' )
 
     if confirm == 'Yes':    
         for loopIndex, loopCommand in enumerate(hotkeyDict):
             
             command = loopCommand["command"]
             name    = loopCommand["name"]
             key     = loopCommand["hotkey"]
             alt     = loopCommand["alt"]
             ctl     = loopCommand["ctl"]       
             
             cmds.nameCommand(name, command='python("%s");'%command, annotation=name)
             cmds.hotkey(k=key, alt=alt, ctl=ctl, name=name)
 
             aToolsMod.saveInfoWithUser("hotkeys", name, [key, alt, ctl]) 
             self.updateHotkeyCheck(name)
             
         cmds.savePrefs( hotkeys=True )
コード例 #45
0
ファイル: HotkeyFactory.py プロジェクト: GuidoPollini/MuTools
    def setup_hotKey(self):
        self.validate_hotkeySet()
   
        _press = ''
        if self._valid_cmdPress:
            #_press = mc.nameCommand( self._valid_cmdPress + 'COMMAND', annotation=self._valid_cmdPress, command=self._valid_cmdPress) 
            _press = self._valid_cmdPress
            
        _release = ''
        if self._valid_cmdRelease:
            #_release = mc.nameCommand( self._valid_cmdRelease + 'COMMAND', annotation=self._valid_cmdRelease, command=self._valid_cmdRelease) 
            _release = self._valid_cmdRelease
        
        _d = {'keyShortcut':self._d_fromUI.get('hotkey', self._d_kws['hotkey']),
              'name':_press,
              'releaseName':_release,
              'altModifier':False,
              'ctrlModifier':False,
              'shiftModifier':False}       
        _l_order = ['keyShortcut']
        _modifer = self.validateModifier()
        
        if _modifer and _modifer+'Modifier' in _d.keys():
            _d[_modifer+'Modifier'] = True
            
        if mayaVersion < 2016:
            _d.pop('shiftModifier')
            if _modifer == 'shift':
                log.error("The shiftModifer was added in Maya 2016. Cannot setup.")
                return
        cgmGeneral.log_info_dict(_d,'hotkey args')

        _k = _d.get('keyShortcut')

        log.info(_k)
        log.info(_d)
        mc.hotkey(_k,**_d)#...run it                                        
        mc.savePrefs(hk = True)#...have to save prefs after setup or it won't keep        
コード例 #46
0
def bt_checkCtrFHotkey():

    hotkeyExists = cmds.hotkey('f', query=1, ctl=1)

    if hotkeyExists == 1:
        print 'CTRL f hotkey already exists.  If you\'d like CTRL f to be associated with this tool simply delete the existing hotkey and rerun the tool to auto create.'

    else:
        print 'Automatically setting CTRL f as hotkey for this tool'
        cmds.nameCommand('bt_moveObjToCameraNameCommand',
                         annotation='bt_moveObjToCameraNameCommand',
                         command='bt_moveObjToCamera')
        runtimeCommandExists = cmds.runTimeCommand('bt_moveObjToCamera',
                                                   exists=1)
        if runtimeCommandExists == 0:
            cmds.runTimeCommand(
                'bt_moveObjToCamera',
                category='User',
                command='from bt_moveObjToCamera import *; bt_moveObjToCamera()'
            )
        cmds.hotkey(keyShortcut='f',
                    ctl=1,
                    name='bt_moveObjToCameraNameCommand')
コード例 #47
0
ファイル: hotkey.py プロジェクト: ewerybody/melDrop
def reset(name, config, keyLabel, *args):
    """
    I wish I could actually delete a hotkey completely! But there is no way!
    I can not even hack the userHotkeys.mel and userNamedCommands.mel prefs file!
    Because they might be overwritten anytime.
    """
    prefsDict = prefs.getPrefs()
    if keyLabel not in prefsDict['hotkeyBackups']:
        log.error('keyLabel "%s" could not be found to restore')
        return
    backup = prefsDict['hotkeyBackups'][keyLabel]
    if not backup:
        cmds.hotkey(k=config['key'], name="", alt=config.get('alt', False), ctl=config.get('ctl', False))
        log.info('removed: (%s)' % keyLabel)
    else:
        setHotkey(backup['name'], backup)
        log.info('restored: (%s) %s ' % (keyLabel, backup['name']))
    
    if cmds.runTimeCommand(name, ex=True) and not cmds.runTimeCommand(name, q=True, default=True):
        cmds.runTimeCommand(name, e=True, delete=True)

    prefsDict['hotkeyBackups'].pop(keyLabel)
    prefs.setPrefs(prefsDict)
コード例 #48
0
ファイル: ml_toolbox.py プロジェクト: Italic-/maya-prefs
        def create(self, verbose=False):

            if not self.keys:
                return

            for i, k in enumerate(self.keys):

                name = self.name + "." + self.functions[i]

                if verbose:
                    hotkeyPrint = "\t"
                    if self.altModifier[i]:
                        hotkeyPrint += "[Alt]+"
                    if self.ctrlModifier[i]:
                        hotkeyPrint += "[Ctrl]+"
                    hotkeyPrint = hotkeyPrint + "[" + k + "] :\t" + name
                    print hotkeyPrint

                rtc = "ml_hk_" + self.name + "_" + self.functions[i]

                nc = rtc + "_NC"

                if not mc.runTimeCommand(rtc, exists=True):
                    rtc = mc.runTimeCommand(
                        rtc,
                        default=True,
                        annotation=name + " Hotkey generated by ml_toolbox",
                        category="User",
                        command=self.commands[i],
                    )

                nc = mc.nameCommand(
                    nc, default=True, annotation=name + " nameCommand generated by ml_toolbox", command=rtc
                )

                mc.hotkey(keyShortcut=k, alt=self.altModifier[i], ctl=self.ctrlModifier[i], name=nc, releaseName="")
コード例 #49
0
ファイル: createHotkeys.py プロジェクト: manymax21/dmptools
def setHotkey(hotkey):
    
    # get hotkey dict data
    name = hotkey['name']
    key = hotkey['key']
    alt = hotkey['alt']
    ctl = hotkey['ctrl']
    release = hotkey['release']
    command = hotkey['command']
    if release:
        releaseName = name+"Release"
        releaseCommand = hotkey['releaseCommand']
    
    #create hotkey command
    cmds.nameCommand(name, sourceType="mel", annotation=name, command=command)
    if release:
        cmds.nameCommand(releaseName, sourceType="mel", annotation=releaseName, command=releaseCommand)
    
    # set hotkey
    cmds.hotkey(k=key, alt=alt, ctl=ctl, name=name)    
    #print 'set hotkey:', name, key, alt, ctrl, command

    if release:
        cmds.hotkey(k=key, alt=alt, ctl=ctl, releaseName=releaseName)
コード例 #50
0
ファイル: hotkey.py プロジェクト: ewerybody/melDrop
def getNameCommand(key, ctl=False, alt=False):
    """
    From a key-string plus ctl(bool) and alt(bool) get the internal 'nameCommand'
    that holds the very script code for a hotkey.
    """
    if not isinstance(key, basestring):
        log.error('getNameCommand needs key given as string!')
        return ''
    if len(key) > 1:
        key = key.title()
    # Whow! This is severe! Feeding "hotkey" without such a check kills Maya instantly
    if len(key) == 1 or key in longKeys:
        return cmds.hotkey(key, query=True, alt=alt, ctl=ctl, name=True)
    else:
        log.error('Key invalid: "%s"' % key)
        return ''
コード例 #51
0
def set_hotkey(key,
               name=None,
               command='',
               release_name=None,
               release_command='',
               ctrl=False,
               alt=False):
    if cmds.runTimeCommand("{0}_runtime_cmd".format(name),
                           query=True,
                           exists=True):
        cmds.runTimeCommand("{0}_runtime_cmd".format(name),
                            edit=True,
                            delete=True)

    if cmds.runTimeCommand("{0}_runtime_cmd".format(release_name),
                           query=True,
                           exists=True):
        cmds.runTimeCommand("{0}_runtime_cmd".format(release_name),
                            edit=True,
                            delete=True)

    if name:
        press_runtime_cmd = cmds.runTimeCommand(
            "{0}_runtime_cmd".format(name),
            annotation="{0}_runtime_cmd".format(name),
            command=command,
            commandLanguage="python")

        name_cmd = cmds.nameCommand("{0}_name_cmd".format(name),
                                    annotation="{0}_name_cmd".format(name),
                                    command=press_runtime_cmd)

        cmds.hotkey(keyShortcut=key,
                    ctrlModifier=ctrl,
                    altModifier=alt,
                    name=name_cmd)

    if release_name:
        release_runtime_cmd = cmds.runTimeCommand(
            "{0}_runtime_cmd".format(release_name),
            annotation="{0}_runtime_cmd".format(release_name),
            command=release_command,
            commandLanguage="python")

        release_name_cmd = cmds.nameCommand(
            "{0}_name_cmd".format(release_name),
            annotation="{0}_name_cmd".format(release_name),
            command=release_runtime_cmd)

        cmds.hotkey(keyShortcut=key,
                    ctrlModifier=ctrl,
                    altModifier=alt,
                    releaseName=release_name_cmd)

    cmds.hotkey(autoSave=True)
コード例 #52
0
ファイル: MayaGame.py プロジェクト: Malent3218/MayaGameJam
def SetHotKeys():
    if 'MayaGame' in cmds.hotkeySet(q=True, hotkeySetArray=True):
        cmds.hotkeySet('MayaGame', edit=True, delete=True)
    cmds.hotkeySet('MayaGame', current=True)
    cmds.nameCommand('pushKeyUp',
                     ann='Push Up Key',
                     c='python("MayaGame.PushKeyUp(True)")')
    cmds.nameCommand('pushKeyDown',
                     ann='Push Down Key',
                     c='python("MayaGame.PushKeyDown(True)")')
    cmds.nameCommand('pushKeyLeft',
                     ann='Push Left Key',
                     c='python("MayaGame.PushKeyLeft(True)")')
    cmds.nameCommand('pushKeyRight',
                     ann='Push Right Key',
                     c='python("MayaGame.PushKeyRight(True)")')
    cmds.nameCommand('releaseKeyUp',
                     ann='Release Up Key',
                     c='python("MayaGame.PushKeyUp(False)")')
    cmds.nameCommand('releaseKeyDown',
                     ann='Release Down Key',
                     c='python("MayaGame.PushKeyDown(False)")')
    cmds.nameCommand('releaseKeyLeft',
                     ann='Release Left Key',
                     c='python("MayaGame.PushKeyLeft(False)")')
    cmds.nameCommand('releaseKeyRight',
                     ann='Release Right Key',
                     c='python("MayaGame.PushKeyRight(False)")')
    cmds.hotkey(keyShortcut='Up', name='pushKeyUp', releaseName='releaseKeyUp')
    cmds.hotkey(keyShortcut='Down',
                name='pushKeyDown',
                releaseName='releaseKeyDown')
    cmds.hotkey(keyShortcut='Left',
                name='pushKeyLeft',
                releaseName='releaseKeyLeft')
    cmds.hotkey(keyShortcut='Right',
                name='pushKeyRight',
                releaseName='releaseKeyRight')
コード例 #53
0
ファイル: others.py プロジェクト: elanifegnirf/Snippets
def setUnsetContextHotkeys():
	"""
	This definition sets / unsets context hotkeys.
	"""

	sequence = TRANSFERT_SELECTION_HOTKEY
	command = "python(\"import snippets.libraries.others as others; reload(others); others.transfertSelectionToUserTarget()\")"
	name = "transfertSelectionNamedCommand"
	if cmds.hotkey(sequence, query=True, name=True) != name:
		print("%s | Assigning '%s' hotkey to '%s' command!" % (__name__, sequence, name))
		DEFAULTS_HOTKEYS[sequence] = {"name" : cmds.hotkey(sequence, query=True, name=True),
								"releaseName" : cmds.hotkey(sequence, query=True, releaseName=True)}

		cmds.nameCommand(name, annotation="Transfert Selection", command=command)
		cmds.hotkey(k=sequence, rcr=True, name=name)
	else:
		hotkey = DEFAULTS_HOTKEYS.get(sequence)
		if hotkey:
			print("%s | Unassigning '%s' hotkey from '%s' command!" % (__name__, sequence, name))
			cmds.hotkey(k=sequence, name=hotkey.get("name"), releaseName=hotkey.get("releaseName"))
	return True
コード例 #54
0
                                command=command,
                                commandLanguage="python",
                                category="Custom Scripts")

            cmds.nameCommand("{0}NameCommand".format(name),
                             annotation=annotation,
                             command=name)

        if cmds.hotkeySet(q=True, current=True) == "Maya_Default":
            if not cmds.hotkeySet("Custom", q=True, exists=True):
                cmds.hotkeySet("Custom", current=True)
            else:
                cmds.hotkeySet("Custom", edit=True, current=True)

            cmds.hotkey(keyShortcut="w",
                        ctl=True,
                        sht=True,
                        name="{0}NameCommand".format(name))

        ### Register Menu ###
        MainMayaWindow = mel.eval('$tmpVar=$gMainWindow')
        if cmds.menu('MayaWindow|Welcome_Screen', q=True, ex=True):
            cmds.deleteUI(cmds.menu('MayaWindow|Welcome_Screen', e=1,
                                    dai=True))

        customMenu = cmds.menu('Welcome Screen', parent=MainMayaWindow)
        mn = mel.eval(
            '''menuItem -label "Welcome Screen Show" -command {0} -parent "MayaWindow|Welcome_Screen" show'''
            .format(name))

        welcomescreeninitialized = True
コード例 #55
0
def main():
    print '# Custom Hotkey Set Creation Tool'
    # HotKey Set Creation. Omitting now. Currently
    '''
	### Delete Current Custom Hotkey Sets.
	sSet = 'CustomHotkeySet'
	sSetBU = '%sBU'%sSet# This one is the BU set to be duplicated from.
	aSet = [str(s) for s in cmds.hotkeySet(q = True, hotkeySetArray = True)]

	# Delete previously created Custom Hotkey Sets.
	if sSet in aSet:
		cmds.hotkeySet(sSet, edit = True, delete = True)
		print '%s found. Deleted.'% sSet
	if sSetBU in aSet:
		cmds.hotkeySet(sSetBU, edit = True, delete = True)
		print '%s found. Deleted.'% sSetBU

	# Create a fresh custom Set. (Create BU first for Toggle tool. WIll create sSet at the end of the run.)

	cmds.hotkeySet(sSetBU, current = True)
	print '%s Created.'% sSetBU
	'''

    ### Create Scripts in the Editor. ##

    # Get List of Hotkeys from HotKeys.py
    sScriptName = 'HotKeys'  # remove '.py'
    sScriptPath = '/vol/transfer/dyabu/Scripts/mayaScripts'
    oHotKeys = imp.load_source(sScriptName,
                               '%s/%s.py' % (sScriptPath, sScriptName))

    # Getting List of keys from HotKeys.py (List of all Custom Hotkeys.)
    aKeyList = oHotKeys.KeyList().keys()

    #print aKeyList
    #aKeyList = ['9_N_P','N_ALT_R',] # temp. for testing
    aKeyList = ['L_ALT_P', 'L_ALT_R']  # temp. for testing
    for k in aKeyList:

        if not cmds.runTimeCommand(k, ex=True):

            #mel.eval('runTimeCommand -delete %s '%k) # Not working....
            #cmds.runTimeCommand(k, delete = True)

            aKey = k.split('_')

            # Custom Shortcut command.
            sCommand = '''# Custom Hotkey - Consolidated - v0.0.2

# CUSTOMIZE HERE:
p = '%s/' # Path to HotKeys.py
sChar = '%s' # Key on Keyboard. not case sensitive.
sPress = '%s' # 'P' or 'R' Pressed or Release

# -- Start --
import maya.cmds as cmds
import sys
if p not in sys.path: sys.path.append(p)
import Hotkeys # Hotkeys.py

reload(HotKeys) #Use reload when testing. Comment out when in actual use.

iModifier = cmds.getModifiers()
HotKeys.Execute(sChar, iModifier, sPress)
''' % (sScriptPath, aKey[0], aKey[2])
            aMod = [False, False, False, False]
            if 'SFT' in aKey:
                aMod[0] = True
            if 'CTL' in aKey:
                aMod[1] = True
            if 'ALT' in aKey:
                aMod[2] = True
            if 'CMD' in aKey:
                aMod[3] = True

            sNameCommand = k + aKey[
                2]  # Specific name of the command to assign to a key.
            if 'P' in aKey[2]:
                aRelease = [sNameCommand, False]
            else:
                aRelease = [False, sNameCommand]

            # Key Exceptions
            dExceptions = {
                'SPACE': 'Space',
                'COMMA': ',',
            }
            if aKey[0] in dExceptions.keys():
                sKey = dExceptions[aKey[0]]
            else:
                sKey = aKey[0]

            # Continue here : Shift turns on for some reason
            cmds.runTimeCommand(k,
                                annotation=k.replace('_', ' '),
                                category="Custom Scripts",
                                command=(sCommand),
                                showInHotkeyEditor=1)
            cmds.hotkey(keyShortcut=aKey[0].lower(),
                        sht=aMod[0],
                        ctl=aMod[1],
                        alt=aMod[2],
                        cmd=aMod[3],
                        name=None,
                        rn=None)
            cmds.nameCommand(sNameCommand,
                             ann=k.replace('_', ' '),
                             c=k,
                             stp='python')

            cmds.hotkey(keyShortcut=aKey[0].lower(),
                        sht=aMod[0],
                        ctl=aMod[1],
                        alt=aMod[2],
                        cmd=aMod[3],
                        name=aRelease[0],
                        rn=aRelease[1])
            print '%s : CREATED!' % k
コード例 #56
0
def hotkeySetup():
    """
    """
    # ====================
    # - Runtime Commands -
    # ====================

    # Copy Weights
    if mel.eval('runTimeCommand -q -ex rt_copyWeights'):
        mel.eval('runTimeCommand -e -del rt_copyWeights')
    mel.eval(
        'runTimeCommand -annotation "" -category "User" -commandLanguage "python" -command "import glTools.tools.copyPasteWeights;reload(glTools.tools.copyPasteWeights);glTools.tools.copyPasteWeights.copyWeights()" rt_copyWeights'
    )

    # Paste Weights
    if mel.eval('runTimeCommand -q -ex rt_pasteWeights'):
        mel.eval('runTimeCommand -e -del rt_pasteWeights')
    mel.eval(
        'runTimeCommand -annotation "" -category "User" -commandLanguage "python" -command "import glTools.tools.copyPasteWeights;reload(glTools.tools.copyPasteWeights);glTools.tools.copyPasteWeights.pasteWeights()" rt_pasteWeights'
    )

    # Average Weights
    if mel.eval('runTimeCommand -q -ex rt_averageWeights'):
        mel.eval('runTimeCommand -e -del rt_averageWeights')
    mel.eval(
        'runTimeCommand -annotation "" -category "User" -commandLanguage "python" -command "import glTools.tools.copyPasteWeights;reload(glTools.tools.copyPasteWeights);glTools.tools.copyPasteWeights.averageWeights()" rt_averageWeights'
    )

    # Auto Average Weights
    if mel.eval('runTimeCommand -q -ex rt_autoAverageWeights'):
        mel.eval('runTimeCommand -e -del rt_autoAverageWeights')
    mel.eval(
        'runTimeCommand -annotation "" -category "User" -commandLanguage "python" -command "import glTools.tools.copyPasteWeights;reload(glTools.tools.copyPasteWeights);glTools.tools.copyPasteWeights.autoAverageWeights()" rt_autoAverageWeights'
    )

    # ========================
    # - Create Name Commands -
    # ========================

    copyWtCmd = cmds.nameCommand('copyWeightsNameCommand',
                                 ann='copyWeightsNameCommand',
                                 sourceType='mel',
                                 c='rt_copyWeights')

    pasteWtCmd = cmds.nameCommand('pasteWeightsNameCommand',
                                  ann='pasteWeightsNameCommand',
                                  sourceType='mel',
                                  c='rt_pasteWeights')

    averageWtCmd = cmds.nameCommand('averageWeightsNameCommand',
                                    ann='averageWeightsNameCommand',
                                    sourceType='mel',
                                    c='rt_averageWeights')

    autoAverageWtCmd = cmds.nameCommand('autoAverageWeightsNameCommand',
                                        ann='autoAverageWeightsNameCommand',
                                        sourceType='mel',
                                        c='rt_autoAverageWeights')

    # =============================
    # - Create Hotkey Assignments -
    # =============================

    cmds.hotkey(keyShortcut='c', alt=True, name=copyWtCmd)
    cmds.hotkey(keyShortcut='v', alt=True, name=pasteWtCmd)
    cmds.hotkey(keyShortcut='x', alt=True, name=averageWtCmd)
    cmds.hotkey(keyShortcut='a', alt=True, name=autoAverageWtCmd)
コード例 #57
0
    def _hotkey(self):
        """create hotkey"""
        name = self.ui.line_name.text()
        if cmds.runTimeCommand('%s_press' % name, exists=True):
            if cmds.confirmDialog(m='name is not unique! replace?',
                                  b=['yes', 'no']) == 'no':
                return
            else:
                cmds.runTimeCommand('%s_press' % name, delete=True, e=True)
                cmds.runTimeCommand('%s_release' % name, delete=True, e=True)
        hotkey = self.ui.line_hotkey.text().lower()
        if not hotkey:
            return

        # build menu
        ctrl = self.ui.chb_ctrl.isChecked()
        alt = self.ui.chb_alt.isChecked()
        shift = self.ui.chb_alt.isChecked()
        if self.COMMANDS[self.ui.cmb_method.currentIndex()][0] == "custom":
            press = "MMtoKey.pressCustom(ctl=%s, alt=%s, sh=%s, menu_type=%i, menu_name='%s')"
            press %= ctrl, alt, shift, self.ui.cmb_menu.currentIndex(
            ), self.ui.line_menu.text()
        elif self.COMMANDS[self.ui.cmb_method.currentIndex()][0] == "selected":
            press = "MMtoKey.pressSelected(ctl=%s, alt=%s, sh=%s)" % (
                ctrl, alt, shift)
        else:
            press = "MMtoKey.pressPreset(ctl=%s, alt=%s, sh=%s)" % (ctrl, alt,
                                                                    shift)

        # release command
        if self.COMMANDS[self.ui.cmb_method.currentIndex()][1] == "custom":
            release = "MMtoKey.releaseCustom(command_always=%s, command='%s', language=%i)"
            release %= (self.ui.cmb_menu.currentIndex(),
                        self.ui.line_command.text().replace("'", "\\'"),
                        self.ui.cmb_command.currentIndex())
        elif self.COMMANDS[self.ui.cmb_method.currentIndex()][1] == "selected":
            release = "MMtoKey.releaseSelected()"
        else:
            release = "MMtoKey.releasePreset()"

        # create runtime and name commands
        cmds.runTimeCommand('%s_press' % name,
                            c=press,
                            category='MMtoKey',
                            cl='python')
        cmds.runTimeCommand('%s_release' % name,
                            c=release,
                            category='MMtoKey',
                            cl='python')
        cmds.nameCommand('%s_PressNameCommand' % name,
                         annotation='%s_press' % name,
                         command='%s_press' % name)
        cmds.nameCommand('%s_ReleaseNameCommand' % name,
                         annotation='%s_release' % name,
                         command='%s_release' % name)
        try:
            cmds.hotkey(k=hotkey,
                        name='%s_PressNameCommand' % name,
                        releaseName='%s_ReleaseNameCommand' % name,
                        ctl=ctrl,
                        alt=alt,
                        sht=shift)
        except TypeError:
            cmds.hotkey(k=hotkey,
                        name='%s_PressNameCommand' % name,
                        releaseName='%s_ReleaseNameCommand' % name,
                        ctl=ctrl,
                        alt=alt)
        cmds.warning('hotkey created')
コード例 #58
0
 def buttonPress_resetAll(self):
     _set = self.mi_cgmHotkeyer.validate_hotkeySet()
     log.warning(
         "All hotkeys on {0} set reset to maya defaults".format(_set))
     mc.hotkey(fs=True)
     self.close()
コード例 #59
0
ファイル: JR_hk_map.py プロジェクト: jricker/JR_Maya
	def setCategory(self, category):
		Cache.currentCategory = category # set hotkey category to selected
		self.categoryHotkeys() # intializes the nameCommands
		cmds.headsUpDisplay('categoryHUD', edit=True, c = self.displayCategory ) # update HUD with hotkey category
		#
		if category == 'modeling':
			mel.eval('setPolyCountVisibility 1')
		else:
			mel.eval('setPolyCountVisibility 0')
		#
		# GLOBAL HOTKEYS
		# `
		cmds.hotkey( k='`', name= 'tilde' ) # tilde
		cmds.hotkey( k='`', alt=True, name= 'alt_tilde' ) # Alt + tilde
		cmds.hotkey( k='`', ctl=True, name= 'ctrl_tilde' ) # Ctrl +  tilde
		# 1
		cmds.hotkey( k='1', name= 'one' ) # one
		cmds.hotkey( k='1', alt=True, name= 'alt_one' ) # Alt + one
		cmds.hotkey( k='!', name= 'shift_one' ) # Shift + one
		# 2
		cmds.hotkey( k='2', name= 'two' ) # two
		cmds.hotkey( k='2', alt=True, name= 'alt_two' ) # Alt + two
		###
		## CHANGE THIS IF WE'RE USING A US KEYBOARD - FOR UK ONLY RIGHT NOW!!!
		###
		cmds.hotkey( k='"', name= 'shift_two' ) # Shift + two = UK KEYBOARD
		cmds.hotkey( k=u'@', name= 'shift_two' ) # Shift + two = US KEYBOARD
		# 3
		cmds.hotkey( k='3', name= 'three' ) # three
		cmds.hotkey( k='3', alt=True, name= 'alt_three' ) # Alt + three
		cmds.hotkey( k=u'£', name= 'shift_three' ) # Shift + three = UK KEYBOARD
		cmds.hotkey( k=u'#', name= 'shift_three' ) # Shift + three = US KEYBOARD
		# 4
		cmds.hotkey( k='4', alt=True, name= 'alt_four' ) # Alt + four
		# 5
		cmds.hotkey( k='5', alt=True, name= 'alt_five' ) # Alt + five
		# Q
		cmds.hotkey( k='q', name= 'q', releaseName = 'q_release' ) # q
		cmds.hotkey( k='q', alt=True, name= 'alt_q') # Alt + q
		# W
		cmds.hotkey( k='w', name= 'w', releaseName = 'w_release' ) # w
		# E
		cmds.hotkey( k='e', name= 'e', releaseName = 'e_release' ) # e
		cmds.hotkey( k='e', ctl=True, name = 'ctrl_e' ) # Ctrl + e
		# R
		cmds.hotkey( k='r', name= 'r', releaseName = 'r_release' ) # r
		cmds.hotkey( k='R', name= 'R' ) # R
		cmds.hotkey( k='r', ctl=True, name = 'ctrl_r' ) # Ctrl + r
		cmds.hotkey( k='r', alt=True, name = 'alt_r' ) # Alt + r
		# H
		cmds.hotkey( k='h', name= 'h' ) # h
		# L
		cmds.hotkey( k='l', ctl=True, name = 'ctrl_l' ) # Ctrl + l
		# P
		cmds.hotkey( k='p', alt=True, name = 'alt_p', releaseName = 'alt_p_release' ) # Alt + p
		cmds.hotkey( k='p', ctl=True, name = 'ctrl_p' ) # Ctrl + p
		# F
		cmds.hotkey( k='F', name= 'F' ) # F
		# B
		cmds.hotkey( k='b', alt=True, name= 'alt_b' ) # ctrl + b
		# M
		cmds.hotkey( k='m', name = 'm' ) # m
		cmds.hotkey( k='M', name = 'M' ) # M
		cmds.hotkey( k='m', ctl=True, name = 'ctrl_m' ) # Ctrl + m
		cmds.hotkey( k='M', ctl=True, name = 'ctrl_M' ) # Ctrl + M	
		# D
		cmds.hotkey( k='d', name= 'd' ) # d
		cmds.hotkey( k='d', alt=True, name= 'alt_d' ) # Alt + d
		# I
		cmds.hotkey( k='i', name= 'i' ) # i
		cmds.hotkey( k='i', alt=True, name= 'alt_i' ) # Alt + i
		cmds.hotkey( k='i', ctl=True, name= 'ctrl_i' ) # Ctrl + i
		# O
		cmds.hotkey( k='o', name= 'o' ) # o
		# G
		cmds.hotkey( k='g', alt=True, name= 'alt_g') # alt + g
		# C
		cmds.hotkey( k='c', name= 'c', releaseName = 'c_release') # c
		cmds.hotkey( k='c', alt=True, name= 'alt_c') # alt + c
		cmds.hotkey( k='C', alt=True, name= 'alt_shift_c') # alt + shift + c
		# V
		cmds.hotkey( k='v', name= 'v', releaseName = 'v_release') # v
		# CATEGORY HOTKEYS
		# X
		cmds.hotkey( k='x', name= 'x', releaseName = 'x_release') # x
		cmds.hotkey( k='x', alt=True, name= category + '_alt_x' ) # Alt + x
		# C
		cmds.hotkey( k='C', name= category + '_C', releaseName = 'C_release' ) # Shift + c
		# E
		cmds.hotkey( k='e', alt=True, name= category + '_alt_e' ) # Alt + e
		# S
		cmds.hotkey( k='S', name= 'S' ) # S
		cmds.hotkey( k='s', alt=True, name= 'alt_s' ) # Alt + s
		cmds.hotkey( k='S', alt=True, name= 'alt_S' ) # Alt + shift + s
		cmds.hotkey( k='S', ctl=True, name= 'ctrl_S' ) # Ctrl + Shift + s
コード例 #60
0
def setHotkeys(pref):
    '''set hotkeys according to pref dictionary'''
    #first reset
    resetHotkeys()
    hotkeys = hotkeyDict[pref]
    #outliner
    cmds.nameCommand( 'OutlinerWindowNameCommand', ann='OutlinerWindowNameCommand', c='OutlinerWindow')
    cmds.hotkey( k=hotkeys[1], alt=hotkeys[0], name='OutlinerWindowNameCommand', releaseName='')
    #attribute editor
    cmds.nameCommand( 'AttributeEditorNameCommand', ann='AttributeEditorNameCommand', c='AttributeEditor')
    cmds.hotkey( k=hotkeys[2], alt=hotkeys[0], name='AttributeEditorNameCommand', rn='')
    #graph editor
    cmds.nameCommand( 'GraphEditorNameCommand', ann='GraphEditorNameCommand', c='GraphEditor')
    cmds.hotkey( k=hotkeys[3], alt=hotkeys[0], name='GraphEditorNameCommand' )
    #tool settings
    cmds.nameCommand( 'ToolSettingsWindowNameCommand', ann='ToolSettingsWindowNameCommand', c='ToolSettingsWindow')
    cmds.hotkey( k=hotkeys[4], alt=hotkeys[0], name='ToolSettingsWindowNameCommand' )
    #trax editor
    cmds.nameCommand( 'CharacterAnimationEditorNameCommand', ann='CharacterAnimationEditorNameCommand', c='CharacterAnimationEditor')
    cmds.hotkey( k=hotkeys[5], ctl=True, name='CharacterAnimationEditorNameCommand' )
    if lib.checkAboveVersion(2015):
        #versions below 2016 don't have shift modifier in hotkey command
        #special key
        cmds.nameCommand( 'SpecialKeyNameCommand', ann='Set a Special Keyframe', c='python("import coopAnimUtils;coopAnimUtils.keySpecial()")')
        cmds.hotkey( k=hotkeys[6], alt=True, name='SpecialKeyNameCommand' )
        #breakdown key
        cmds.nameCommand( 'BreakdownKeyNameCommand', ann='Key only keyed attributes', c='python("import coopAnimUtils;coopAnimUtils.keyInbetween()")')
        cmds.hotkey( k=hotkeys[6], sht=True, name='BreakdownKeyNameCommand' )
    #curvesel key TODO
    #cmds.nameCommand( 'ScriptEditorNameCommand', ann='ScriptEditorNameCommand', c='ScriptEditor')
    #cmds.hotkey( k=hotkeys[6], sht=True, name='ScriptEditorNameCommand' )
    #script editor
    cmds.nameCommand( 'ScriptEditorNameCommand', ann='ScriptEditorNameCommand', c='ScriptEditor')
    cmds.hotkey( k='i', alt=True, name='ScriptEditorNameCommand' )

    print pref + " hotkeys set (to change or reset hotkeys, right mouse click on the same shelf button\n",