import maya.cmds as cmds
# Relative value increase
cmds.keyframe(edit = True, iub = True, relative = True, vc = 0.1)
import maya.cmds as cmds
# Relative value decrease
cmds.keyframe(edit = True, iub = True, relative = True, vc = -0.1)
Solved! Go to Solution.
Solved by Kahylan. Go to Solution.
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!
Can't find what you're looking for? Ask the community or share your knowledge.