[Closed] Set Key script equivalent?
What’s the scripted equivalent of Set key. I’m wanting my tool to work in Set Key mode and when I press my scripted button it has to create a key with the current value.
So my guess was
addNewKey $[3][1][1] currentTime #select #interpolate
which seems to advertise that I should pickup the interpolated value of the controller at that time. But it still uses the value from the controller, before Set Key mode was on. So now I’m wondering how do I mimic the SetKey functionality… It’s not a macroscript that I can have a look at unfortunately. Any insights on the set key process would be welcome! I know I can capture the current transform and store that and loop over it etc etc… but is that what Set Key is then?!
Thanks!
-Johan
A cheap hack would be something like this:
defaultKey = maxops.autoKeyDefaultKeyOn
maxops.autoKeyDefaultKeyOn = false
with animate on (
at time ((currenttime as integer)/ticksperframe) ($[3][1][1].value = $[3][1][1].value)
)
maxops.autoKeyDefaultKeyOn = defaultKey
Basically turn off the autokey the default frame and then with animate on, at the desired time, set the value equal to itself.
-Eric
for set key mode, there is:
max set key keys
max set key on selected
something i don’t know is how to add a key on a specific track, like x
@Eric : I don’t want autokey I want set Key, and I tried the with animate on trick to pass the value on to itself, but in set Key mode that (strangly!) doesn’t work, and it grabs the values from the controller instead of the setKey temporary value! So that really made me wonder how set key works under the hood.
The solution that does work is to specificly target each bezier_float controller and set the values there instead of the position_XYZ controller. addNewKey to a XYZ controller works and creates the keys, but it ignores the setKey values, targetting each subcontroller at a time does seem to work though.
@Ruramuq : Those keys don’t help me, because I want to set position to something like smooth keys and rotation to step keys. Right now you can only select 1 type of keyframes for all types of controllers that get a Set Key.
I still wonder how Set Key works under the hood, because if it’s not easy to do in maxscript, then what happens in the depths of the maxscript core…?
-Johan
That’s been my technique for years… laborious but it works every time…
JHN did you ever get some insight on this?
I have been having a problem that I think is similar to yours… I’m trying to set keys on an object through maxscript but it’s not respecting the keys. I’ve tried using animate on, maxOps.setKeyMode, operating on position_xyz, operating on individual x y z controllers, pretty much everything that I can think of but it doesn’t matter, scripting a keyframe doesn’t work.
First key is where I place it, then second key just modifies the first key to move to the 2nd key’s position, as well as creating a 2nd key. It’s almost like each key is behaving like an instance or something, very strange behavior.
I’m pretty much locked in production, so I haven’t had time to work on this. The problem you are describing about the 2nd keyframe I haven’t seen that myself.
Do you add a new key to a parent controller or the actual x, y or z controller. The behaviour differs from these two when using addNewKey.
-Johan
I’ve tried both, I’m now working on the individual xyz controllers.
Currently I’m trying to add a new key, and then set the value of the key afterwards. Seems counterintuitive (addNewKey should automatically set the value as current with the #interpolate flag, I would expect) but it’s as close as I’ve gotten to a successful result.
I’ve not done much with AddNewKey…
[font=Verdana]
I generally use a nested key set function like so… just affecting values, then return to the key arrays to set in’s, out’s and curve ratios… ect…
(
tnBox = Box()
Animate on
(
At time 5
tnBox.position = [10,10,10]
At time 25
tnBox.position = [50,50,50]
)
-- delete Key at zero, because I don't want it.
deleteItem tnBox.position.controller.keys 1
-- set beizer out
tnBox.position.controller.x_position.keys[1].outTangentType = #custom
tnBox.position.controller.y_position.keys[1].outTangentType = #custom
tnBox.position.controller.z_position.keys[1].outTangentType = #custom
[/font][font=Verdana][/font][font=Verdana]-- set beizer in on key 2
tnBox.position.controller.x_position.keys[2].inTangentType = #custom
tnBox.position.controller.y_position.keys[2].inTangentType = #custom
tnBox.position.controller.z_position.keys[2].inTangentType = #custom
)
[/font][font=Verdana]
Might be an easier way, but this works for me… It can be long arduous code, so write some functions…
[/font]
for whatever reason, animate on does nothing for me in this case. i’m trying to set keys on nurbs curves with limit controllers on them, so what i’m having to do to get any key to stay put is the following:
tmpX = in coordsys parent each.pos.x
tmpY = in coordsys parent each.pos.y
maxOps.setKeyMode = true
if each.pos.x_position.controller[1] != undefined do
k1 = addNewKey each.pos.x_position.controller[1].controller currentTime
if each.pos.y_position.controller[1] != undefined do
k2 = addNewKey each.pos.y_position.controller[1].controller currentTime
k1.value = in coordsys parent tmpX
k2.value = in coordsys parent tmpY
it’s clunky because it requires the set key box to be on, but otherwise if i try to set 2 keys and have it interpolate, it sets the first one, i move the object, set another key, and it moves the 1st to the 2nd’s position and sets a key. i can then use the curve editor to pull the first one around, and that works, but it doesn’t maintain the key for some reason.