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

insert keys in active or selected curve, Graph editor

3 REPLIES 3
Reply
Message 1 of 4
dg3duy
173 Views, 3 Replies

insert keys in active or selected curve, Graph editor

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.gif

3 REPLIES 3
Message 2 of 4
mcw0
in reply to: dg3duy

Just add the name of the curve you want to act on to your commands

Message 3 of 4
Kahylan
in reply to: dg3duy

Hi!

 

Well, you an use the animCurveEditor command to check which curves are shown and then use a loop to set the names of those curves as args in the the setKeyframe command, if you want to have a keyframe on the same frame for every diplayed curve. Or you can set the name of the curves as args in the findKeyframe commands as well so you have a keyframe at that percentage relative to every curve.

 

But that would then render the program completely useless if the grapheditor isn't open or if there isn't any curve selected in it...

So you would have to first check if that is the case and then either run the function in "grapheditor mode" or in "timeline mode". Ofcourse you'd need to decide wether the grapheditor should have influence if it is just open or if it needs to be the panel in focus to matter, since that changes the way you will be querring for it.

And then you would have to decide how you want to split your grapheditor mode and timeline mode.

1) If they are decided in your checking function and always pass the names of all the active curves, the checking function just querries differently depending on the mode

2) If only grapheditor mode passes curve names and the insertKeyPercentage function works as a hybrid that decides how to act wether it gets passed curve names or not

3) If you want to have your grapheditor mode as an entirely new function and decide which function gets run in your checking function using an if else statement.

 

Ofcourse if you have a mode that discriminates based on the graph editor, why not also have a mode that dicriminates based on Channelbox Attribute selection, would make sense, right? So you have to decide all those things again for your channelbox mode and determine which mode has priority and based on what criteria...

 

Thats how I would approach a change like this. I won't write this as code though, since it is a lot of work and testing and some decisions that I can't take without a lot more information on the project...

 

I hope it helps!

Message 4 of 4
Cagetron
in reply to: dg3duy

Ya you have to tell it which curves. In the past for this kind of thing I've done the visible ones in the graph editor, or if multiple are visible, the ones with keyframes selected. Put in a check for if the graphEd is open if you want to get fancy. hope this helps

In mel to get the visible curves from the graph editor you can do something like:

string $selConn = `editor -q -selectionConnection graphEditor1OutlineEd`;
string $activeCurves[] = `findAnimCurves($selConn)`;

 

If keys are selected:

string $activeCurves[] = `keyframe -q -n`;

 

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report