0

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?

ErezProductions
  • 41
  • 3
  • 11
  • This works as written: selecting something and pressing f5 -f8 moves the object. However it is not continuous - you need to press the key multiple times – theodox Jul 31 '15 at 21:49
  • So how can I make it continuous? – ErezProductions Jul 31 '15 at 22:02
  • You can't, not without hacking the main maya QT window. Maya only reacts to presses and releases – theodox Jul 31 '15 at 22:10
  • 1
    Do you know how to hack it ? Is it legal? – ErezProductions Jul 31 '15 at 22:21
  • @theodox Well I tried it without writing the function, how ever, it doesnt move even a little bit, and I pressed like 100 times – ErezProductions Jul 31 '15 at 22:44
  • a) It's legal, but not trivial: You need to learn how to work with QT signals and intercept them. You might find somebody at tech-artists.org who knows how. b) the code above works if you execute the whole thing once - for the duration of that session f5-f8 will move selected objects. Because you use setAttr instead of xform it only works on objects (not components) – theodox Jul 31 '15 at 23:44
  • @theodox so you are telling me that there is no way to create games in Maya, that need pressing like that? without hacking the software? – ErezProductions Aug 01 '15 at 00:07
  • @theodox The QT is a software isn't it? Do you know how can I hack it into Maya? – ErezProductions Aug 01 '15 at 00:29
  • well maya is not a game engine so its hard to do it. And hacking QT events also will not be that successful. And if you copy a code from another question link it – Achayan Aug 01 '15 at 00:32
  • The closest you could do to creating a game inside of maya would be to use the motion capture API to create a plugin that would do live updates. I think that only works while animations are playing, however. If you want to make a game use Maya to make the content but program it in Unity – theodox Aug 01 '15 at 17:26
  • @theodox do you know if there is an option to - make an object move while I long press the hotkey in Maya LT ? because I did that and it worked only when I pressed and left the button over and over again. – ErezProductions Aug 02 '15 at 12:18
  • That's what I mean: press and release, but no hold in Maya. – theodox Aug 02 '15 at 20:31
  • Copying answer from another question and pasting to another thread without link is not a fair job :). And if the answer help'd you then upvote that. – Achayan Aug 04 '15 at 17:14

0 Answers0