# Findkeyframe Command

**URL:** https://forum.highend3d.com/t/findkeyframe-command/1046
**Category:** Maya
**Tags:** mel
**Created:** [May 6, 2009, 2:30pm UTC](https://forum.highend3d.com/t/findkeyframe-command/1046 "2009-05-06T14:30:02Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![cyberika](https://forum.highend3d.com/user_avatar/forum.highend3d.com/cyberika/32/98_2.png) [@cyberika](https://forum.highend3d.com/u/cyberika)
#### Post date: [May 6, 2009, 2:30pm UTC](https://forum.highend3d.com/t/findkeyframe-command/1046/1 "2009-05-06T14:30:02Z")

</div>

Hi!  
Can't make work this code correctly

CODE  
string $sel[] = `ls -sl -transforms`;  
string obj;

&nbsp;&nbsp;for($obj in $sel)  
&nbsp;&nbsp;{

int $ini\_f =`findKeyframe -timeSlider -which next`;  
int $fin\_f =`findKeyframe -timeSlider -which previous`;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string $kfRange2 = ($ini\_f+":"+$fin\_f);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print ($kfRange2+"\n");

&nbsp;&nbsp; }

there is few objects. Each of this objects have 2 kayframes in different frame. Objective is to get frames that have keyframes and insert : symbol between.  
loop returns selections last objects values.

---

<div class="post-metadata">

### Author: ![joojaa](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@joojaa](https://forum.highend3d.com/u/joojaa)
#### Post date: [May 6, 2009, 8:05pm UTC](https://forum.highend3d.com/t/findkeyframe-command/1046/2 "2009-05-06T20:05:19Z")

</div>

Find next keyframe works on a selection set. The flag -timeSlider is intended for the timeline view querry change so it can not be passed individual objects in bigger selection without wasting considerable time.

CODE  
{  
&nbsp;&nbsp;string $sel[] = `ls -sl -transforms`;  
&nbsp;&nbsp;string $obj;

&nbsp;&nbsp;for($obj in $sel)  
&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;int $ini\_f =`findKeyframe -animation objects -which next $obj`;  
&nbsp;&nbsp;&nbsp;&nbsp;int $fin\_f =`findKeyframe -animation objects -which previous $obj`;  
&nbsp;&nbsp;&nbsp;&nbsp;string $kfRange2 = ($ini\_f+":"+$fin\_f);  
&nbsp;&nbsp;&nbsp;&nbsp;print ($kfRange2+"\n");  
&nbsp;&nbsp;}  
&nbsp;&nbsp;//select -r $sel;  
}

PS: put code inside CODE

```auto
 and QUOTE
```

tags its a bit hard to show it in this foum properly because those tags turn into tags

---

<div class="post-metadata">

### Author: ![cyberika](https://forum.highend3d.com/user_avatar/forum.highend3d.com/cyberika/32/98_2.png) [@cyberika](https://forum.highend3d.com/u/cyberika)
#### Post date: [May 6, 2009, 8:20pm UTC](https://forum.highend3d.com/t/findkeyframe-command/1046/3 "2009-05-06T20:20:48Z")

</div>

Thanks Joojaaa !  
I've just founded the solution too ) .

CODE  
string $sel[] = `ls -sl -transforms`;  
string $obj;

&nbsp;&nbsp; for($obj in $sel)  
&nbsp;&nbsp;{

select $obj;  
int $ini\_f =`findKeyframe  -time 0 -which next`;  
int $fin\_f =`findKeyframe  -time 48 -which previous`;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string $kfRange2 = ($ini\_f+":"+$fin\_f);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print ($kfRange2+"\n");

&nbsp;&nbsp; }

In this case I nee 2 value more. First one indicates 1 frame of time range and second one last frame but I choose yours ![]()

---

<div class="post-metadata">

### Author: ![joojaa](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@joojaa](https://forum.highend3d.com/u/joojaa)
#### Post date: [May 6, 2009, 8:29pm UTC](https://forum.highend3d.com/t/findkeyframe-command/1046/4 "2009-05-06T20:29:46Z")

</div>

Its always faster to pass selections to the commands than to select and act on that. Because managing the selection s quite heavy thing and needs undo too and that wastes memory.
