How to move an object with hot keys in Maya python

时间:2015-07-31 20:35:17

标签: python move maya hotkeys autodesk

well I got this piece of code-

def moveCurrent(direction):
    getSel = cmds.ls(sl=True)
    if getSel:
        if direction == "up":
            currentVal = cmds.getAttr("%s.tx" % getSel[0])
            cmds.setAttr("%s.tx" % getSel[0], currentVal + 10)
        elif direction == "down":
            currentVal = cmds.getAttr("%s.tx" % getSel[0])
            cmds.setAttr("%s.tx" % getSel[0], currentVal - 10)
        elif direction == "left":
            currentVal = cmds.getAttr("%s.tz" % getSel[0])
            cmds.setAttr("%s.tz" % getSel[0], currentVal - 10)
        elif direction == "right":
            currentVal = cmds.getAttr("%s.tz" % getSel[0])
            cmds.setAttr("%s.tz" % getSel[0], currentVal + 10)

cmds.nameCommand( 'moveCurrentSelectionFuncUp', ann='Move Selected Mode', c='python("moveCurrent(\\\"up\\\")")' )
cmds.nameCommand( 'moveCurrentSelectionFuncDown', ann='Move Selected Mode b', c='python("moveCurrent(\\\"down\\\")")' )
cmds.nameCommand( 'moveCurrentSelectionFuncLeft', ann='Move Selected Mode c ', c='python("moveCurrent(\\\"left\\\")")' )
cmds.nameCommand( 'moveCurrentSelectionFuncRight', ann='Move Selected Mode d ', c='python("moveCurrent(\\\"right\\\")")' )
cmds.hotkey( keyShortcut='F5', name='moveCurrentSelectionFuncUp' )      
cmds.hotkey( keyShortcut='F6', name='moveCurrentSelectionFuncDown' ) 
cmds.hotkey( keyShortcut='F7', name='moveCurrentSelectionFuncLeft' ) 
cmds.hotkey( keyShortcut='F8', name='moveCurrentSelectionFuncRight' )

this code works only if I call the function and enter a direction into it. How ever, I want the object to move if I just press the hot keys, I dont want to call the function manually, I want it to happen if the specified hot key is pressed - if F5 is pressed, so the object moves up..it can be any other hot key. Is it possible?

0 个答案:

没有答案