Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
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: 

Keys delete delay script

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
434 Views, 4 Replies

Keys delete delay script

I'm trying to make a script to delete the keys before and after on my current selected key. I'm not good enough in python scripts. but I tried this. But Sadly its failed. can any one help me out to fix this.

 

cmds.cutKey(‘pSphere1_translateX’, clear=1, time=(2, 300))

 

What i want?

Suppose I'm on key frame 20, then i want to delete 5 keys before and after from current(20) keyframe.

 

 

Tags (1)
Labels (2)
4 REPLIES 4
Message 2 of 5
mcw0
in reply to: Anonymous

First query the time values of your keyframes.

Find the index of the current frame.

Then construct your cutKey command to remove 5 indices before and after the current index.  I can't remember but you may be able to define more than one index range.  I'm pretty sure you can.  Otherwise, once you cut the first index range, you'd need to update the post index range since it will be different after removing the pre index range.

Message 3 of 5
Anonymous
in reply to: mcw0

Hi, 

Can you please elaborate with formula here as example.  So I could understand visually here..

 

Thanks  a lot for reply here.

Message 4 of 5
mcw0
in reply to: Anonymous

To get the frames of your animation curve:

float $frames[] = `keyframe -q -tc "your_anim_curve"`;

 

Now let's say your current frame is 100.  Loop through the $frames array to find which index is "100".

 

int $currentFrameIndex;

for($i=0;$i<size($frames);$i++)

{

    if($frames[$i] == 100)

    {

        $currentFrameIndex = $i;

        break;

    }

}

 

Now you can cut the keys you want.  5 frames fore and aft.

 

cutKey -index (($currentFrameIndex-5)+":"+($currentFrameIndex-1)) 

 

That will cut the 5 frames before your current frame.  Of course, you need the rest of the cutKey command options to finish that command.

 

Now that you have deleted those frames, the $currentFrameIndex is no longer relevant.  So you need to update it.  It has shifted 5 indices forward. 

 

$currentFrameIndex -= 5;

 

Now construct the cutKey command for the aft 5 frames.

 

cutKey -index (($currentFrameIndex+1)+":"+($currentFrameIndex+5)) 

 

I'm typing this here without testing this in Maya.  But that is the general idea.  

 

 

Message 5 of 5
mcw0
in reply to: mcw0

Sorry, I just realized you did your code in Python.  But it's pretty straightforward to convert MEL to Python.  Let me know if you have any issues.

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

Post to forums  

Autodesk Design & Make Report