[Closed] addNewKey
Hi, first, excuse my english.
I am trying create a custom Attributes with AddKey Button. Create key button well, but the object not apply the transforms why?
this is code:
a = box()
md = EmptyModifier ()
addmodifier a md
def = attributes keyAttrib
(
rollout rKey "add Key"
(
Button kButton "Add"
on kButton pressed do
(
t = slidertime
p = a.pos.controller
r = a.rotation.controller
addNewKey p t
addNewKey r t
print "Addkey"
)
)
)
CustAttributes.add md def
What kind of transforms do you expect to get?
When you set a new key, it gets the current value.
But if you go to a different frame and transform the object while AutoKey is off, the existing keys will all be shifted relatively and store any transforms you are applying. So when you press the button again, yet another key with the SAME value as all other keys will be created.
addNewKey() should generally be used to get the return value of the created key and then set its .value to whatever you want. But what you have written does not implement the Set Key functionality in Max which actually keeps track of the old and the new value at the current time without changing existing keys and sets the new value when you press the Key button, thus avoiding the relative shift of all other keys.
So if you wanted to set the position or rotation to some random value for example, your code could easily be expanded to do that. But if you want to replicate the Set Key feature, you will have to use its exposure – addNewKey pre-dates that by 3 versions of Max and has no knowledge of that system at all…
Unless I am misunderstanding what you are trying to do.