Community
Maya Animation and Rigging
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya animation topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How do I create a hotkey to increase or decrease the value of the selected key?

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
amaterasu-qbb
358 Views, 2 Replies

How do I create a hotkey to increase or decrease the value of the selected key?

To change the value in the Graph Editor, use SHIFT + MMB (middle mouse button) and move vertically up and down to change the value.
To change the timing in the Graph Editor, use SHIFT + MMB and move horizontally left and right to change the timing.

 

My complaint is that the judgment of whether the mouse cursor is moved vertically or horizontally while pressing SHIFT + MMB in the Graph Editor is very strict.

 

Depending on the angle of the mouse cursor, the timing moves when you originally wanted to move the value. The opposite also happens.

 

The commands in this link allowed me to change the timing back and forth on one frame with a hotkey. So it made my work very convenient.
 
This time I want to increase or decrease the value, plus or minus 1.0 increments.
the result of Echo All Commands

 

 

//Increases the value of a key that is selected in the Graph Editor.

selectKey -clear ;
selectKey -add -k -t 1 pCube1_translateZ ;
doUpdateTangentFeedback;
dR_updateCounter;
updateAnimLayerEditor("AnimLayerTab");
statusLineUpdateInputField;
if (!`exists polyNormalSizeMenuUpdate`) {eval "source buildDisplayMenu";} polyNormalSizeMenuUpdate;
ikSelectionChanged("MayaWindow|mainKeysMenu|menuItem1991|ikFKStateItem");
ilrUpdateSpreadSheetEditor;
ilrUpdateAEDeferred;
dR_updateCommandPanel;
ilrUpdateAE;
keyframe -e -iub true -r -o over -vc 1.715638 -t 1 pCube1_translateZ ;
doUpdateTangentFeedback;

//Decreases the value of a key that is selected in the Graph Editor.

selectKey -clear ;
selectKey -add -k -t 1 pCube1_translateZ ;
doUpdateTangentFeedback;
dR_updateCounter;
updateAnimLayerEditor("AnimLayerTab");
statusLineUpdateInputField;
if (!`exists polyNormalSizeMenuUpdate`) {eval "source buildDisplayMenu";} polyNormalSizeMenuUpdate;
ikSelectionChanged("MayaWindow|mainKeysMenu|menuItem1991|ikFKStateItem");
ilrUpdateSpreadSheetEditor;
ilrUpdateAEDeferred;
dR_updateCommandPanel;
ilrUpdateAE;
keyframe -e -iub true -r -o over -vc -1.797335 -t 1 pCube1_translateZ ;
doUpdateTangentFeedback;

 

 

Common commands are,
keyframe -e -iub true -r -o over -vc 1.715638 -t 1 pCube1_translateZ ;

I converted it from MEL to Python in my own way,

 

 

import maya.cmds as cmds

cmds.ls(sl = True)
cmds.keyframe(edit = True, iub = True, r = True, o = over, vc = 1, t = 1)

 

 

But the result is.
# Error: NameError: file <maya console> line 4: name 'over' is not defined

Any help you can lend would be greatly appreciated.

Thanks,
Tags (2)
Labels (2)
2 REPLIES 2
Message 2 of 3

Hi! everyone.

 

I would like to inform you all.

I have created a command that allows you to increase or decrease the value of the selected key.

I hope you all will try to use it. I would appreciate your help in giving me feedback. Thank you.

 

The command increases or decreases the value of the key in the graph editor by 0.1, so in some cases, this value may be too much or too little.

I would like to ask for a programming forum to evaluate and fix my code. but please feel free to report it in this post as well.

 

I will accept the solution to this post for now, once I have assigned my command to a hotkey and confirmed that the command works.
If you have any good ideas, please let me know.

 

This is the code to increase the value of the key.

import maya.cmds as cmds

# Relative value increase
cmds.keyframe(edit = True, iub = True, relative = True, vc = 0.1)

This is the code to decrease the value of the key.

import maya.cmds as cmds

# Relative value decrease
cmds.keyframe(edit = True, iub = True, relative = True, vc = -0.1)

 

Message 3 of 3

An update of the code has been published by @Kahylan . Special thanks!
original link of the code.
 
@Kahylan wrote:

Hi!

 

It works, so that is good. It's a good start into coding.

Two minor suggestions to your code:

1) The flag iub is set to True by default, so you don't need to add it to your command to get the desired effect.

2) I would either have all your flags in long form or all of them in short form. It doesn't make a difference, it just makes it seem more professional.

import maya.cmds as cmds

# like this
cmds.keyframe(e = True, r = True, vc = 0.1)

# or this
cmds.keyframe(edit = True, relative = True, valueChange = 0.1)

 

Now as you mentioned correctly, a big problem with your command is that it feeds a static value at the moment, which depending on scene scale could be way to high or way too low. I thought I'd present a possible solution to this problem.

 

Creating an option variable (a variable that gets stored in Mayas preferences) to scale the value up and down, combined with a UI that would be called via script or shelf button to easily set the option variable. It would look something like this.

 

Make value bigger hotkey command:

import maya.cmds as cmds

#check if optionVar exists, if it doesn't set it to default value
if cmds.optionVar(ex = "animationValueChangeFloat")== 0:
    cmds.optionVar(fv = ("animationValueChangeFloat", 0.1))
    
#get Value from optionVar
changeValue = cmds.optionVar(q= "animationValueChangeFloat")   

#change keyframe value
cmds.keyframe(e = True, r = True, vc = changeValue)

Make value smaller hotkey command:

import maya.cmds as cmds

#check if optionVar exists, if it doesn't set it to default value
if cmds.optionVar(ex = "animationValueChangeFloat")== 0:
    cmds.optionVar(fv = ("animationValueChangeFloat", 0.1))
    
#get Value from optionVar
changeValue = cmds.optionVar(q= "animationValueChangeFloat")   

#change keyframe value
cmds.keyframe(e = True, r = True, vc = (-1 * changeValue))

 

Command to call UI from shelf button:

import maya.cmds as cmds


def buildChangeUI():
    windowName = "animationValueChangeUI"
    
    if cmds.window(windowName, ex = True):
        cmds.deleteUI(windowName)
    
    cmds.window(windowName)
    v = getValue()
    cmds.columnLayout("mainLayout")
    sliderGrp = cmds.floatSliderGrp("ChangeSliderGRP" , l= "Change Value", f = True, min=0, max = 10, fmx = 100000,pre= 3, v= v)
    cmds.floatSliderGrp(sliderGrp , l= "Change Value", e=True, cc = lambda x = cmds.floatSliderGrp(sliderGrp, q= True, v= True): changeOptionVar(value = x))
    cmds.showWindow(windowName)

def getValue():
    if cmds.optionVar(ex = "animationValueChangeFloat")== 0:
        cmds.optionVar(fv = ("animationValueChangeFloat", 0.1))
        changeValue= 0.1
    else:
        changeValue = cmds.optionVar(q= "animationValueChangeFloat")
    return changeValue    
    
def changeOptionVar(value = None):
    cmds.optionVar(fv= ("animationValueChangeFloat", value))

buildChangeUI()

 

Option Variables are stored in the preferences, so this approach will change the value in all scenes on the same machine, you could also approach it more localised by storing the value on a node in the scene.

 

I hope it helps!


The last code can be registered on the shelf and will be the code to adjust the value in the UI. The value can be adjusted by sliding or typing in the value and is very easy to use.
How to use this code.


How to use this code.
  1. Register the code on the shelf
  2. Click the registered code to activate it.
  3. Type or drag any value to set.
  4. Select a key in the Graph Editor.
  5. Use the hotkeys assigned Make value bigger hotkey command and Make value smaller hotkey command.

That is all you need to do to adjust the value of the key. A feature of this code is that the UI values are preserved even when the UI window is closed.
If you want to use a value of 0.1 as per the hotkey values in the Make value bigger hotkey command and the Make value smaller hotkey command, you have to reopen the UI and type 0.1.
The reason is that the value is stored in:

 

 

changeValue = cmds.optionVar(q= "animationValueChangeFloat")

 

I am sorry, but I am going to Accept Solution to share this code with you.
Please note that I do not own this Accept Solution, even though it may increase my ranking in the Top Solution Authors.

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report