Change the tangent type in first and last keyframe

In my animation curve I am using Auto Tangents for any the keyframes, but how do I specify the first and the last keyframe to be in Spline Tangents by using python?

I tried coding in this manner:

cmds.keyTangent( q=True, index = 0, g = 1, itt = "spline", ott = "spline")

but I got the error - # TypeError: Invalid arguments for flag ‘index’. Expected (index, [index]), got int #

try this:

cmds.keyTangent( q=True, index = (0, 0), g = 1, itt = "spline", ott = "spline")

[QUOTE=rgkovach123;26127]try this:

cmds.keyTangent( q=True, index = (0, 0), g = 1, itt = "spline", ott = "spline")

[/QUOTE]

Hey rgkovach123, tried out your code in my code, it does not seems to be working.
But when tried it out as a one-liner, I am seeing the following error in the editor: # TypeError: Flag ‘itt’ must be passed a boolean argument when query flag is set #

try this

inTangentType = cmds.keyTangent( q=True, index = (0, 0), itt = True)
outTangentType = cmds.keyTangent( q=True, index = (0, 0), ott = True)

[QUOTE=rgkovach123;26137]try this

inTangentType = cmds.keyTangent( q=True, index = (0, 0), itt = True)
outTangentType = cmds.keyTangent( q=True, index = (0, 0), ott = True)[/QUOTE]

Also does not seems to be working as well… :x

Quickly, I know how to do it on frames by applying it on the first and last. Is it necessary to be key indices? The only problem left is that you need to drop the query flag in order to apply a new value. Using a different state flag like edit, or query changes the behavior of the command and at the same time, the inputs it is expecting. This should work:

from maya import cmds

def adjust_tangents( inNode ):
	
	# Get the curves.
	anim_curves = cmds.listConnections( inNode, type='animCurve' )
	
	# Apply the new tangent on the first and last keys.
	for anim in anim_curves:
		keys = cmds.keyframe( anim, query=True )
		cmds.keyTangent( anim, time=( keys[0], ), inTangentType='spline', outTangentType='spline' )
		cmds.keyTangent( anim, time=( keys[-1], ), inTangentType='spline', outTangentType='spline' )

adjust_tangents( <your_animated_node_here> )

Hope it helped.

G

[QUOTE=gpz;26143]Quickly, I know how to do it on frames by applying it on the first and last. Is it necessary to be key indices? The only problem left is that you need to drop the query flag in order to apply a new value. Using a different state flag like edit, or query changes the behavior of the command and at the same time, the inputs it is expecting. This should work:

from maya import cmds

def adjust_tangents( inNode ):
	
	# Get the curves.
	anim_curves = cmds.listConnections( inNode, type='animCurve' )
	
	# Apply the new tangent on the first and last keys.
	for anim in anim_curves:
		keys = cmds.keyframe( anim, query=True )
		cmds.keyTangent( anim, time=( keys[0], ), inTangentType='spline', outTangentType='spline' )
		cmds.keyTangent( anim, time=( keys[-1], ), inTangentType='spline', outTangentType='spline' )

adjust_tangents( <your_animated_node_here> )

Hope it helped.

G[/QUOTE]

Hey gpz, sorry for the late reply…
It seems to be working in my cause. Gonna try to incorprate the code into the code that I have written.
Any ideas why by adding in a query flag (as the one posted by rgkovach123) does not works? Pardon me, but I thought that at times when trying to modify something within the object etc, query or edit should do the trick?

So would this means that what I am trying to achieve isn’t part of this sort of modification?

Query and edit both do different things. Edit is used to modify existing objects while query is used to gather information. The command “addAttr” is a good example to understand the difference. Let’s say you use the flag “niceName.” If you use it as is, it will assign a nice name to the attribute that you are creating. If you combine it with edit, it will change the nice name of an attribute that already exists. Finally, if you combine it with query, it will return the nice name of an attribute that already exists. Since the command can do three different things, those flags allow you to tell it what you want it to do.

Sometimes, the difference between create and edit can be very thin. In your case, I think that edit mode would make no difference ( I do not have access to Maya to confirm that though.) However, query would make a difference since it is meant to retrieve data not to apply it. Also take note that flags sometimes are mutually exclusive. They can be incompatible with other flags for logical reasons. A good example is the “g” flag that you were using with keyTangent command. This flag sets the “default” tangent type to apply when setting a keyframe. In your case it does not apply, and it is not compatible with time values since it is a global thing. I hope I make sense here.

Anyway, hope the concept is clearer. Happy coding! :smiley:

G

Thanks gpz, for the info! I did tried out in both query and edit flags before, but as it is not working, I can only concludes that either I am still missing some other flags/variables within my command or, I am not coding it right, probably as you have mentioned - the time values as a global thing…

Thanks again!