Insert keys in active or selected curve, Graph editor

89 views
Skip to first unread message

Darwin Giordano

unread,
Aug 12, 2022, 8:10:45 PM8/12/22
to Python Programming for Autodesk Maya

How is it possible to make this code work but that it works with each active curve, and does not apply in the other curves the keys since it incorporates them in places where I do not want them to be.

import maya.cmds as mc
def insertKeyPercentage(percentage = 100):
key1 = mc.currentTime(q = True)

 key2 = mc.findKeyframe(t = (key1,key1), w = "next")


 keyx = mc.findKeyframe(t = (key1,key1), w = "previous")

 p = ((key2-keyx)/100)*percentage


 newKey = mc.setKeyframe(i = True, t = (key2 -p/2)) 


insertKeyPercentage(percentage = 100)

curves GROUPS.gif



Roman Perrin

unread,
Aug 13, 2022, 7:01:33 AM8/13/22
to python_in...@googlegroups.com
Hi, 
You get the names of the anim Curves that you want.  You can loop in a list of those if there's more than 1. And you add it as the first argument of setkeyframe. 

Cordialement
Perrin Roman

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/8e31de18-8de2-499c-b63e-92c9990fdef5n%40googlegroups.com.

Darwin Giordano

unread,
Aug 13, 2022, 10:28:52 AM8/13/22
to Python Programming for Autodesk Maya

Any example of how to execute what you tell me, so I can do it from an example, it is very difficult for me to understand it without seeing an example.
Thank you very much.

Roman Perrin

unread,
Aug 17, 2022, 5:14:21 AM8/17/22
to python_in...@googlegroups.com
hey sorry for the wait,

curves =cmds.keyframe(sl=True, q=True, n=True) #this get the name of the animcurve of the selected key

curves = cmds.animCurveEditor('graphEditor1GraphEd', curvesShown=True, q=True) #this return the names of the animcurves that are shown in the graph editor

and then a for loop
for curve in curves
    key1 = mc.currentTime(curve, q = True)
    key2 = mc.findKeyframe(curve, t = (key1,key1), w = "next")
.......
    cmds.setKeyframe(curve, i = True, t = (key2 -p/2))

Regards
PERRIN Roman

Darwin Giordano

unread,
Aug 17, 2022, 12:15:29 PM8/17/22
to Python Programming for Autodesk Maya
Thank you very much for answering,... I understand it better with the example you write, what happens now is that there is something in the syntax that gives error.
Maybe in this part it is missing something else or it is written in another way?


and then a for loop
for curve in curves

Reply all
Reply to author
Forward
0 new messages