PDA

View Full Version : Color coding if keyed -- help!


Bleen
04-18-2006, 07:46 PM
Hello, I have little experience with MEL so please go easy on me :-)

I'm trying to color code the controls for a face of a character... if they're keyed.
For example, if the animator keys the "smile" control, the control curve itself would change from being blue to red. This way the animator can scrub through the animation and see what controls are keyframed!
But alas, my MEL knowledge is reduced...
I tried using the docs, but I only got more confused. I tried searching the forums, but found nothing. So far I've been testing and I have these chunks of code:

int $tiempo = `currentTime -q`;
$haykey[] = `keyframe -t $tiempo -query Smile_ctrl`;
if ($haykey[1] != 0)
print "There's a key here!";
else
print "NO KEY";

To test if "Smile_ctrl" is keyed at current time. Which returns systax error on the $haykey declaration line. I only need to know if anything inside the control curve's keyed. If at least one attribute is keyed, color code it to red...

I also have a doubt, would an expression such as this evaluate every frame automatically?

Thanks!

Stucky
04-19-2006, 11:25 PM
I changed the code to this:


float $haykey[] = `keyframe -query Smile_ctrl`;

if ($haykey[0] != 0)

print "There's a key here!";

else

print "NO KEY";


I deleted the first line, because you don't need to query what is the current time. And in the second line, you just have to query if the object is keyed, you don't need to point the time. Then it will print something, whether it IS keyframed or NOT.


Hope this helps


-S

Bleen
04-21-2006, 06:18 PM
Stucky, thanks! It DOES help, however, I'm still puzzled about what keyframe -query Ctrl_name returns.

I made a keyframe on frame 2, printed the line and I got this:
print `keyframe -query Ctrl_name`;
2
2
2
2
2
2
2
2
2
2
2


This particular control has 11 keyframeable channels (the 3xTranslate, 3xRotate, 3xScale, and two custom attributes).

So I was thinking this command returns a string array, in which every position in the array is a channel. But no matter in which frame I queried it, it allways returned the same string. So I was really confused about what this command returns.
I made a keyframe on frame 9, and, again, printed the command. This was the outcome:
print `keyframe -query Ctrl_name`;
2
9
2
9
2
9
2
9
2
9
2
9
2
9
2
9
2
9
2
9
2
9


So it seems it creates a string array, in which every position indicates the time of a keyframe! :-/

So now I really don't know how to make the computer know if there's a keyframe on the current frame or not. I was thinking of going position by position, comparing the current time to the value of the position...

Any ideas or code? ;)

Thanks! :wavey:

Stucky
04-22-2006, 02:00 AM
Yes. There is a solution for you. imagine you have a cube called pCube1. You can query if it is keyframed only in one frame, or in a frame range.

Say, frame 10:


keyframe -time 10 -query pCube1;

Say, frame range 5 to 10:

keyframe -time "5:10" -query pCube1;

And you can also query only one of its attributes. Like:

keyframe -time 10 -query pCube1.translateX;


Hope this helped...

If you need more help. Just ask...


-S

Bleen
04-25-2006, 03:06 PM
Thanks! :love:

EUREKA!


int $ctime = `currentTime -q`;
$ckey = `keyframe -time $ctime -query pCube1`;
$sumkey = 0;
$index = 0;
for ($i in $ckey)
{
$sumkey = $sumkey + $ckey[$index];
$index = $index + 1;
}
int $keyframed;
if ($sumkey == 0)
{
$keyframed = 0;
setAttr "pCube1.overrideEnabled" 0;
}
else
{
$keyframed = 1;
setAttr "pCube1.overrideEnabled" 1;
}

And this actually WORKS ! :bounce:
I just input this code into an expression and it evaluates every frame.

The only catch was to change the object's override color previously. This way, I turn on the override when the object's keyed.
I wanted to actually leave the override on and just change the color, but I couldn't find how to do this. If anyone knows, feel free to comment on this

Now I'd need to:
1) Find a way to automate the application of this expression to a list of selected objects
2) Find a way for this to work with objects in different layers, with different base colors. Now this only works with objects wich are not with an override color (which ocurrs if they are not in any layer or changed by the user).
Thanks for your help :love:

CGTalk Moderation
04-25-2006, 03:06 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.