Python API "addKeysWithTangents" is not functioning correctly.

Python API "addKeysWithTangents" is not functioning correctly.

icapathos
Advocate Advocate
460 Views
4 Replies
Message 1 of 5

Python API "addKeysWithTangents" is not functioning correctly.

icapathos
Advocate
Advocate

I tried "addKeysWithTangents" to set a number of keyframes at once.

It create keyframes with right values at right frames.

But, it cannt make right tangents, all tangents are being generated as "fixed".

 

 

import maya.OpenMayaAnim as oma

# mplug : find a MPlug
fnAnim = oma.MFnAnimCurve(mplug)

# create array to set keyframes
for time, value, inTangent, ... in all_my_data:
  timeArray.append( time )
  valueArray.append( value )
  tangentInTypeArray.append( inTangent )
  ...

fnAnim.addKeysWithTangents(timeArray, valueArray, oma.MFnAnimCurve.kTangentGlobal, oma.MFnAnimCurve.kTangentGlobal, tangentInTypeArray, tangentOutTypeArray, tangentInXArray, tangentInYArray, tangentOutXArray, tangentOutYArray, tangentsLockedArray, weightsLockedArray)

 

 

 

Do you have any other examples of using the API correctly? I would like to know the proper way to use it.

0 Likes
Accepted solutions (1)
461 Views
4 Replies
Replies (4)
Message 2 of 5

brentmc
Autodesk
Autodesk
Accepted solution

Hi,

 

If you supply values for the tangents then the type will be set to fixed to preserve the values you have supplied.

If you do not want this then don't supply tangent values and Maya will compute them based on the type you specify.

Brent McPherson
Principle Engineer
0 Likes
Message 3 of 5

icapathos
Advocate
Advocate

Thanks to you, I can use the API

Message 4 of 5

icapathos
Advocate
Advocate

I have another question.

When I use the python api "addKeysWithTangents", can I "undo" the command?

After run addKeysWithTangents, it is not included in undo queue.

0 Likes
Message 5 of 5

brentmc
Autodesk
Autodesk

In Maya commands are undoable but the API is (in general) not since it is operating at a lower level.

So, if you want this to be undoable you would have to wrap this up in a command and do the undo yourself or use Maya commands (like setKeyframe) which are undoable.

Brent McPherson
Principle Engineer
0 Likes