PDA

View Full Version : How to know when an object has been moved?


svintaj
11-19-2003, 03:11 PM
Hi

The only way I know is to connect a scriptJob to an specific objects specific attribute, but I want to know when any object has been moved or rotated, or maybe resently been keyframed?

/ Svante

dwalden74
11-19-2003, 03:48 PM
I want to know when any object has been moved or rotated, or maybe resently been keyframed

What do you mean by "recently"? In the past minute? Hour? Year?You can check if a file has been changed since the last time you saved it with `file -q -amf`.

svintaj
11-19-2003, 04:06 PM
Ok, with "recently" I ment "almost real time"

/ Svante

dwalden74
11-19-2003, 06:12 PM
Ok, its still a bit general though. You need to compare values relative to some starting value (i.e., zero, since the file was opened/saved, etc), so how do you know what your starting value is? I think you might be right that the only way to do this would be via scriptJob (event attr changed).

svintaj
11-19-2003, 06:55 PM
Well, what I want to do is to run my MEL script if an
"autoKey-event" has occur, but i gess there is no such event.

I could use scriptJob with the -attributeChange flag, but I have to create a scriptJob for every-selected-objects-every-keyable-attribute.

I'm new to MEL and I just wonder if there is a more simple way, like one scriptJob insted of maybe 20 ?
Maybe this in't so bad as I first thought... :shrug:

/ Svante

brubin
11-19-2003, 07:17 PM
just as one thought...

you know how to use global variables now, don't you? ;)

you keyframe with autokey only on selected objects, right?

well, you could feed a global variable with what ever is selected when selection changes (that works as a scriptjob)
the last element of that global array variable (you could select more than one object) is your last selected object.

there is a way to count keyframes on objects. after your selection changes find out howmany keyframes there are already.
a second scriptjob checks if that number changes. if so -> do something else!

you end up with two easy scriptjobs and a couple of arrays.

HIH
s.

svintaj
11-19-2003, 08:39 PM
Nice tought, but in my case I also need to check if existing keyframes are "autoKeframe updated"

Is it in someway bad to use lots of scriptJobs?

Thanks for your help :cool:

/ S

mark_wilkins
11-19-2003, 09:03 PM
Lots of scriptJobs will slow things down.

So what is it that you're really trying to do? Maybe there's a more direct way to get to the goal you're after than to check whether anything has been keyed in the scene.

-- Mark

svintaj
11-19-2003, 10:20 PM
I am writing a script wich can preserve edited key-tangents, Mayas AutoKey don't care and just use the default key-type and thats why I write this script, it will be like an AutoKeyAdjust feature.

If I can do this in a simple way I will go :cry: :applause: :surprised
, cause I'm almost done...

/ S

mark_wilkins
11-19-2003, 10:25 PM
I've always thought Autokey was the work of the devil, but if you can get your script working, more power to you. :D

-- Mark

dwalden74
11-20-2003, 06:47 AM
I've always thought Autokey was the work of the devil

I find it heaven-sent for animation. ;)

mark_wilkins
11-20-2003, 06:50 AM
Yeah, but you have no control over what you're keying!!! In a complex animation pipeline, keying attributes you don't intend can make all kinds of things break in subtle and spectacular ways.

Of course, Autokey can be great for pose-based workflows, but I've been party to lots of people getting into serious trouble because they forgot to turn it off at critical moments.

-- Mark

dwalden74
11-20-2003, 07:07 AM
Heya mark-

Yeah, but you have no control over what you're keying!!!

Sure you do! Every value that has been modified since the last keyframe is keyed. But you already know that, Im sure. Its quite simple really.

I've been party to lots of people getting into serious trouble because they forgot to turn it off at critical moments

Yes, well, Im sorry for those people, but you certainly have to pay attention to what youre doing while animating in a 3d package.

I always have in mind the following when animating:

1) type of keyframe interpolation.
2) current character set.
3) is auto-key On or Off.


...works great for me.


:beer:
David

mark_wilkins
11-20-2003, 07:10 AM
Yes, well, Im sorry for those people, but you certainly have to pay attention to what youre doing while animating in a 3d package.

It's easy to say that, but this particular mistake seems to cut across all levels of experience with 3D or Maya, at least among the animators I've worked with. (Often the problem comes from running scripts that fiddle with attributes without their being fully aware of the detail.)

-- Mark

dwalden74
11-20-2003, 08:09 AM
It's easy to say that, but this particular mistake seems to cut across all levels of experience with 3D or Maya, at least among the animators I've worked with

Being aware of whether or not auto-key is activated or not, is one of the most important things an animator must learn and keep in mind when animating. This is simply a question of proper training. I wouldnt really understand if an animator came to me and said that his scene was messed up because he didnt know that auto-key was on.


Often the problem comes from running scripts that fiddle with attributes without their being fully aware of the detail

Yes, this might be more of the issue that youre talking about. But, Im not sure what you mean exactly? You mean scripts that turn auto-key on/off?

mark_wilkins
11-20-2003, 08:15 AM
no, I mean running a script that does a bunch of setAttrs while autokey is turned on, thus setting keys on those attributes when it's not intended.

It's training, it's having the rigs set up with the right things locked, it's keeping an awareness of autokey going in the scripts, but as your crew gets to 25+, code base gets larger, shot count goes up, etc. you'll find that everyone makes these kinds of mistakes with Autokey often enough to be irritating, unless they just don't use it.

Admittedly, the long-term cost savings probably outweigh that troubleshooting.

-- Mark

dwalden74
11-20-2003, 09:07 AM
it's having the rigs set up with the right things locked

well that's certainly true. You also mentioned 'setAttr'. I'm sure you know that auto-key only keys attrs that have already been keyed (it doesn't just keyframe any attr you change in the scene). So if you ran any 'setAttr' commands on animated attrs, it would be assumed that you'd want to key them anyway.

Of course, if you're working with a pose-based system (and I'd assume most places are), then it's not really a big deal to go in and delete any inadvertent keyframes....

:beer:
David

brubin
11-20-2003, 08:31 PM
Originally posted by svintaj
I am writing a script wich can preserve edited key-tangents, Mayas AutoKey don't care and just use the default key-type and thats why I write this script, it will be like an AutoKeyAdjust feature.

If I can do this in a simple way I will go surprised , cause I'm almost done...



so before this thread gets completely hijacked let me add another thought:

// inside your script create a namedCondition called (e.g.) "isAutoKeyOnCondition"
condition -d autoKeyframeState -s "checkAutoKeyState" isAutoKeyOnCondition ;

int $whatEverSJ = `scriptJob -conditionChange "isAutoKeyOnCondition" "doWhateverWithAutokey"` ;


// don't forget to do this when you're done
// or the window closes!!
// condition -delete isAutoKeyOnCondition ;
// scriptJob -kill $whatEverSJ -force;

global proc doWhateverWithAutokey()
{
// query the current tangent type and remember it
string $currentTangentType[] ;
$currentTangentType = `keyTangent -q -global -itt -ott` ;

// define what happens when autokey is ON
if (`isTrue autoKeyframeState`)
{
// now set it to whatever you want
keyTangent -e -global -itt flat -ott spline ;

// do whatever els you like, i.e. print :)

string $autoKeyTangentType[] ;
$autoKeyTangentType = `keyTangent -q -global -itt -ott` ;
print ("current tangent type \(global\) \= \""+$autoKeyTangentType[0]+"\" \""+$autoKeyTangentType[1]+"\"\n") ;
}

// if autokey is OFF
if (!`isTrue autoKeyframeState`)
{
// restore to the old tangent type
string $inTangentType = $currentTangentType[0] ;
string $outTangentType = $currentTangentType[1] ;
// now set it to whatever you want
keyTangent -e -g -itt $currentTangentType[0] -ott $currentTangentType[1] ;

// do whatever els you like, i.e. print :)
print ("restored tangent type \(global\) \= \""+$inTangentType+"\" \""+$outTangentType+"\"\n") ;
}
}

// this is the script called by the namedCondition "isAutoKeyOnCondition"
// it get's evaluated whenever autoKey's state is changed to ON or OFF
global proc int checkAutoKeyState()
{
// if autokey is ON
return (`isTrue autoKeyframeState`) ;
}


// autokey uses the (global) tangent settings!! so make sure you set these correctly before you use them.
because: autokey is good!
;)

there's something i don't really get, though: autokey creates new keys on already animated attributes. that includes adjusting an already existing keyframe. that you would only want to do if that old keyframe sucked, right? if the key changes so does the tangent. what is the point of preserving it then? or am i missing something here?

HIH
s.

mark_wilkins
11-21-2003, 06:59 AM
Originally posted by dwalden74
I'm sure you know that auto-key only keys attrs that have already been keyed (it doesn't just keyframe any attr you change in the scene).

Yeah, but because of certain historical (possibly already fixed) bugs in referencing, many animators have gotten into the habit of setting a key on EVERYTHING before they start working.

-- Mark

dwalden74
11-21-2003, 08:45 AM
whoa, that sounds wierd mark.:eek: Well then, I see your point.

svintaj
11-21-2003, 10:29 AM
there's something i don't really get, though: autokey creates new keys on already animated attributes. that includes adjusting an already existing keyframe. that you would only want to do if that old keyframe sucked, right? if the key changes so does the tangent. what is the point of preserving it then? or am i missing something here?

You have missed the most important point!

I don't want AutoKey to change my tangent when I move an object. I don't want AutoKey to act like a new key is created.
I want to keep my edited in and out key settings, even if I move or rotate my object. It's equal to: if all rotations and translations were reseted when I modify it's tangent, how fun would that be?

**It's crazy that Mayas autoKey kills my tangent settings!!!**


It's not useful for me to know if autoKey is on or off, but thanks man.

My script is roughly done, but it's buggy and i dont have time to fix it right now, I have lots of animation to do :wip:
To bad I cant use it in this project...

Must animate!
/ Svante

dwalden74
11-21-2003, 10:53 AM
**It's crazy that Mayas autoKey kills my tangent settings!!!**

I agree, but it's not just auto-key. setKeyframe will do the same thing... it's just the nature of the beast. I would like to see a "Set new tangents on overwritten keys" preference, which we could deselect to preserve our tangents while we over-key.

brubin
11-21-2003, 01:13 PM
Originally posted by dwalden74
I agree, but it's not just auto-key. setKeyframe will do the same thing... it's just the nature of the beast.

EXACTLY! this ist the core of the poodle! you (svintaj) want to fight windmills!

don't be no george-doubleyou, do the smart thing instead, don't use the standard "keyframe"-command, create your own!

one that will always remember the keytangents already made, and keeps them in mind or restores them after a new keyframe.

admittedly that's a "hack"-approach, and it will not reeeeally work with autokey, but there's hope, a lot of issues that colleagues and i had to write hacks for ever since maya v.1.0.1, eventually became real features in newer versions, with proper and bugfree re-writes or additions to existing features of the code.

sorry mate, that's the best one can do at this point.
s.

svintaj
11-22-2003, 02:11 PM
My script is working for straight keyframing but it will not
run bug-free with autokey mode...

I will attatch a call to this function to my "s" key:

global proc SetKey_KeepTangents() {

PickUpTangents();
setKeyframe;
ApplyTangents();

}

It works werry well, so far no bugs :)
But to make AutoKey work I'm doing this:

If ( time changed ){ // A scriptJob checks for this
PickUpTangents2();
}
If ( attribute changed ){ // A scriptJob checks for this
ApplyTangents2();
}

This is also working but with some bugs like:
If I edit tangents in the GraphEditor my script will auto-undo the changed tangents :blush:
So I have to deactivate my script if the GraphEditor is active...
I hope it's possible, to bad there is no "AutoKeyCreated event"

Maybe the API have something i can use???

Must go back and animate...
/ Svante

mark_wilkins
11-23-2003, 02:30 AM
If you use the keyframe -edit command, you can change the value of a keyframe without affecting tangents, just as though you had dragged it to a different value in the graph editor:

For example, if I run the command on a sphere with a key at time 60:


keyframe -edit -time 60 -valueChange 4 nurbsSphere1.ty;


this will change the value of that keyframe leaving its tangents intact.

You could wrap this in a short script that would check for a keyframe (using keyframe -q) then use setKeyframe if no keyframe exists or keyframe -edit if a keyframe does exist.

-- Mark

svintaj
11-23-2003, 11:51 AM
Ok, thank you Mark!
I didn't know there was a keyframe -edit command.
I will write my own AutoKey-function and use this command in that script. It will be much more simple to do!

I still have to check if the object has moved, and I will check this with an "attributeChange ScriptJob" on every-selected-objects-animateble-attribute.

Grate!:thumbsup:

/ Svante

CGTalk Moderation
01-16-2006, 05:00 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.