Results 1 to 9 of 9

Thread: Change the tangent type in first and last keyframe

  1. #1

    Default 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:
    Code:
    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 #

  2. #2
    Technical Artist
    Join Date
    Jul 2008
    Location
    Austin, TX
    Posts
    677

    Default

    try this:

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

  3. #3

    Default

    Quote Originally Posted by rgkovach123 View Post
    try this:

    Code:
    cmds.keyTangent( q=True, index = (0, 0), g = 1, itt = "spline", ott = "spline")
    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 #

  4. #4
    Technical Artist
    Join Date
    Jul 2008
    Location
    Austin, TX
    Posts
    677

    Default

    try this

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

  5. #5

    Default

    Quote Originally Posted by rgkovach123 View Post
    try this

    inTangentType = cmds.keyTangent( q=True, index = (0, 0), itt = True)
    outTangentType = cmds.keyTangent( q=True, index = (0, 0), ott = True)
    Also does not seems to be working as well.. :x

  6. #6
    Maya dude
    Join Date
    Nov 2014
    Location
    Montreal, Canada
    Posts
    16

    Default

    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:

    Code:
    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

  7. #7

    Default

    Quote Originally Posted by gpz View Post
    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:

    Code:
    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
    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?

  8. #8
    Maya dude
    Join Date
    Nov 2014
    Location
    Montreal, Canada
    Posts
    16

    Default

    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! :D

    G

  9. #9

    Default

    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!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •