Community
Maya Forum
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

I want to create a hotkey to toggle between Weighted Tangent and Non-Weighted Tangent.

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
amaterasu-qbb
326 Views, 2 Replies

I want to create a hotkey to toggle between Weighted Tangent and Non-Weighted Tangent.

Hi! everyone

I am currently writing code to toggle between Weighted Tangent and Non-Weighted Tangent for the Graph Editor keys. To assign it to a hotkey. I found that this command can be used to toggle between Weighted Tangent and Non-Weighted Tangent.

 

import maya.cmds as cmds

cmds.keyTangent(wt = True)

import maya.cmds as cmds

cmds.keyTangent(wt = False)

I want to switch using the if, but I can't do it. Why is it not working? What part of the program can I fix to have it work?

import maya.cmds as cmds

cmds.keyTangent(wt = True)

if cmds.keyTangent(wt = True):
    cmds.keyTangent(wt = False)

else: cmds.keyTangent(wt = True)

https://help.autodesk.com/view/MAYAUL/2024/ENU/?guid=__CommandsPython_index_html

Note: switching a curve from weightedTangents true to false and back to true again will not preserve fixed tangents properly.

I agree with this. Any advice you can give me would be appreciated.

 

Thanks,

Labels (2)
2 REPLIES 2
Message 2 of 3

Sorry for the late reply, @Anonymous on Twitter gave me the code: https://forums.autodesk.com/t5/maya-programming/python-using-if-and-else-to-toggle-between-a-weighted-tangent/td-p/1201111
The following code is based on the code he gave me. I hope it is useful.

 

import maya.cmds as cmds

# Toggle Weighted Tangent, Non-Weighted Tangents.
cmds.keyTangent(e = True, wt = not(cmds.keyTangent(q = True, wt = True)[0]))
import maya.cmds as cmds

# Toggle Weighted Tangent, Non-Weighted Tangents by selected Anim Curves.
selectedCurves = cmds.keyframe(q=True,name = True,selected = True) or []
for selectedCurve in selectedCurves:
    cmds.keyTangent(selectedCurve,e = True,wt = not(cmds.keyTangent(selectedCurve,q = True, wt = True)[0]))

 


Also, @Kahylan gave me a modified version of the code I posted in my Maya forum question. I think this will be useful as well.

 

import maya.cmds as cmds

# set to Non-Weighted Tangents, False.
if cmds.keyTangent(q = True, wt = True) == [True]:
    cmds.keyTangent(e = True, wt = False)

# toggle Weighted Tangents.
else:
    cmds.keyTangent(e = True, wt = True)

 

 

Thanks,

 

I Accept Solution to this answer but this is not by me, it was helped by @Anonymous and @Kahylan. But I accept the solution because it helps the community.
I would like to take this opportunity to thank @Anonymous and @Kahylan

Message 3 of 3

Thanks to @Anonymous and @Kahylan's help, I was able to create a code to toggle between Lock Tangent Length and Free Tangent Length, so I will post it here as well.

import maya.cmds as cmds

# Toggle Lock Tangent Length or Free Tangent Length.
cmds.keyTangent(e = True, wl = not(cmds.keyTangent(q = True, wl = True)[0]))

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report