[Closed] Select Keyframes and Change its Value
Hey guys,
I have an atribute holder with a spinner value that goes from 0 to 10.
In many points of the animation i have keyframes setted in 2. Is there a way to select only those especific keyframes and change it’s values, let’s say, to 1?
Just in case, here’s the scene:
https://www.dropbox.com/s/664s9g2j1qv8f32/CGTalk%20-%20Asteroids%20keyframe.rar
EDIT: The keyframes are on the Dummy001
Thank’s
Cool, by thinking about your problem I found a solution to a problem I had at work yesterday!
I never tried to manipulate keys on controllers before, but with these MaxKeyArrays its much easier than I thought.
Anyways here is the code for your scene:
-- Create a MaxKeyArray
keyCycle = $Dummy001.modifiers[#Attribute_Holder].Custom_Attributes.Noise.keys
-- Cycle trough the MaxKeyArray and change the value of the key with animate on.
for k in keyCycle do
(
with animate on
(
if k.value == 2 do k.value = 1
)
)
You should be able to just run it like that.
for key in <anyfloatsuperclasscontroller>.keys where key.value == 2 do key.value = 1
the faster way is to collect keys with value 2 and set them at once
keys = for key in <anyfloatsuperclasscontroller>.keys where key.value == 2 collect key
if keys.count > 0 do keys.value = 1
Like this?
fn setKeyValue obj findVal: newVal: prop: =
(
if isKindOf obj.modifiers[1] EmptyModifier and isProperty obj.modifiers[1] prop do
(
if (keys = obj.modifiers[1].noise.keys).count != 0 do
(
keys = for k in keys where k.value == findVal collect k
if keys.count != 0 do keys.value = newVal
)
)
)
setKeyValue $Dummy001 findVal:2 newVal:1 prop:#Noise
Or you can try this fn. The difference is that you can choose any property of given CA modifier. In this case we modify only “Noise” property
fn setKeyValue obj findVal: newVal: prop: =
(
if isKindOf obj.modifiers[1] EmptyModifier and isProperty obj.modifiers[1] prop do
(
if (keys = obj.modifiers[1].noise.keys).count != 0 do
(
for i = 1 to keys.count where keys[i].value == findVal do
obj.modifiers[1].noise.keys[i].value = newVal
)
)
)
setKeyValue $Dummy001 findVal:2 newVal:1 prop:#Noise
Ah nice, that’s better!
Maybe a simple little interface?
try(destroyDialog ro_ReplaceKeys) catch()
rollout ro_ReplaceKeys "Replace Keys"
(
group "Find and Replace " (
spinner spOld "Old Value:" range: [0,9999,0] type:#float
spinner spNew "New Value:" range: [0,9999,0] type:#float
edittext txtProp "Prop:"
button bnReplace "Replace"
)
fn setKeyValue obj findVal: newVal: prop: =
(
if isKindOf obj.modifiers[1] EmptyModifier and isProperty obj.modifiers[1] prop do
(
if (keys = obj.modifiers[1].noise.keys).count != 0 do
(
keys = for k in keys where k.value == findVal collect k
if keys.count != 0 do keys.value = newVal
)
)
)
on bnReplace pressed do
(
for o in selection do setKeyValue o findVal:spOld.value newVal:spNew.value prop:(txtProp.text as name)
)
) -- End of rollout
createDialog ro_ReplaceKeys
Just enter the old and new values and the name of your prop (in this case Noise)
The for loop seems a little slow though … is there a faster way to do this on multiple objects at once?
Denis showed fastest way.
BTW before for-loop which need to loop trough selection it’s good practice to check if user have selected any object.
try(destroyDialog ::ro_ReplaceKeys) catch()
rollout ro_ReplaceKeys "Replace Key Values"
(
group "Find and Replace "
(
spinner spOld "Old Key Value: " range: [0,9999,0] pos:[9,25] fieldwidth:60
spinner spNew "New Key Value: " range: [0,9999,0] pos:[10,45] fieldwidth:60
edittext txtProp "Property:" pos:[10,65] fieldwidth:110 height:17
button bnReplace "Replace Values" pos:[10,85] width:160 height:18
)
fn setKeyValue obj findVal: newVal: prop: =
(
if isKindOf obj.modifiers[1] EmptyModifier and isProperty obj.modifiers[1] prop do
(
if (keys = obj.modifiers[1].noise.keys).count != 0 do
(
keys = for k in keys where k.value == findVal collect k
if keys.count != 0 do keys.value = newVal
)
)
)
on bnReplace pressed do
(
if selection.count == 0 then messageBox "Select Some Objects First!" title:"Warning" beep:off else
with redraw off (for o in selection do setKeyValue o findVal:spOld.value newVal:spNew.value prop:txtProp.text)
)
)
createDialog ro_ReplaceKeys 180 110 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)