PDA

View Full Version : Trouble: AddNewKey () not returning a key


amv256
06-03-2008, 07:27 AM
I'm trying to add keys to an object's position controller using AddNewKey, but I'm having a weird problem.

If I create a sphere and run the following script:


print $.pos.controller to:debug
q = addNewKey $.pos.controller 50
q.value = [50,50,50]
print q.value to:debug

$.pos.controller = bezier_position ()
print $.pos.controller to:debug
q = addNewKey $.pos.controller 60
q.value = [50,50,50]
print q.value to:debug


I get the following output:


Controller:Position_XYZ
Controller:Bezier_Position
[50,50,50]


Only the second call to AddNewKey () seems to return a working key reference. I also get the following in the MaxScript listener after the first call to AddNewKey ():


-- Unknown property: "value" in OK


In other words, the following apperas to the case:

1) By default, the sphere's position controller is Position_XYZ
2) Adding a new key to this Position_XYZ controller works, but for some reason the function does NOT return a key reference as it should.
3) If I manually add a Bezier_Position controller, a second call to AddNewKey () will also work, but this time, a working reference to a key will be returned as well.

This would make sense if there were no position controller assigned to the sphere at all by default, but there is. Furthermore, AddNewKey () works with this default controller. I see the keyframe pop up on the time slider. But for some reason, the keyframe is not returned from AddNewKey (), which makes no sense to me. Once I add a second controller (which I shouldn't have to do since Position_XYZ is already there), AddNewKey () starts returning an actual reference.

What's going on here?

magicm
06-03-2008, 10:13 AM
2) Adding a new key to this Position_XYZ controller works, but for some reason the function does NOT return a key reference as it should.
Position_XYZ is a compound controller, containing 3 child tracks for X, Y and Z. So calling addNewKey here actually creates 3 keys in the Position_XYZ's child controllers, not the controller itself. The following should work as expected (assuming the X controller has a keyable controller applied):

k = addNewKey $.position.controller[1].controller 50
Which creates a key in the first (X) controller of the Position_XYZ controller.

3) If I manually add a Bezier_Position controller, a second call to AddNewKey () will also work, but this time, a working reference to a key will be returned as well.

Unlike the Position_XYZ controller, a Bezier_Position controller does not have any child tracks, so only one key is created in the track itself.

Cheers,
Martijn

amv256
06-03-2008, 10:31 AM
Thank you so much! It makes perfect sense.

Side question -- I understand that controllers can be layered and given weights to blend their effect, but I've noticed that if I add a bezier position controller for the scripted keys, but have already added manual keyframes (which went into the Position XYZ controller), they seem to work perfectly well together.

I'm actually not 100% sure what I'm trying to ask here, but basically my concern is this: if I add keyframes the traditional way, by hand, they go into Position XYZ-- if I then want to script some, and I happen to add a bezier position controller in order to do so, am I going to have conflicts at some point because I'll have keyframes spread across two separate (but admittedly similar) controllers?


Thanks again!

CGTalk Moderation
06-03-2008, 10:31 AM
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.