Search code examples
pythonmayamaya-api

select nonlinear deformers input node and set keyframe in maya using python?


I want to select and set a key frame in a nonlinear deformers in maya using python script.

What I had tried and failed obviously is based on the knowledge i had on these command.

cmds.setKeyframe('some object name', time='a specific frame', attribute='attribute that i wish to key', value='value i wish to set')

but a nonlinear deformers such as a bend deformer, it seems if you want to set a key in curvature value, you need to specified the name of the input node of the deformer.

in my outliner, i named the deformer as "bend2_handle", using cmds.setKeyframe(), it won't work if use the object name is "bend2_handle", so i have to get the name of the input node: "bend2".

in the script editor, when i manually selected "bend2_handle", it shows in mel command:

select -r bend2_handle ;

when i manually selected bend bend2(where the curvature value is located), it shows in mel command:

select -addFirst bend2 ;

what the heck is a -addFirst. but even if try to use it as the object name, attribute=bend2.curvature, it still won't work, and i know attribute=bend2.curvature is correct, cuz "bend2.curvature" is what i use in cmds.setAttr()

import maya.cmds as cmds
cmds.setKeyframe('bend2', time=12, attribute='bend2.curvature', value=8)
cmds.currentTime(12)
cmds.setAttr('bend2.curvature', 4)
cmds.currentTime(40)
cmds.setAttr('bend2.curvature', 8)

the alternative way i try to achieve is turn on autokeyframe, and manually set a key frame in frame 1,use cmds.currentTiem() to specify the time, and use cmds.setAttr() to change value, therefor add key frame.

But I need to use cmds.setKeyframe() exclusively, no manual operation whatsoever!

can somebody help!?


Solution

  • Just realized that you use "bend1.curvature" as attribute name, here it works if I use only the attribute without "bend1." as attribute name.