ScriptSpot

Forum topic · General Scripting

visibility key problem

By JokerMartini · 2011-03-31

Description

When I run this code it creates a key at the proper frame. But when I create a second key it changes the value of the first key....?

(
fn fnAddVisKey Obj Val =
(
VisTrack = obj.visibility.controller
with animate on
(
newKey = addNewKey VisTrack currentTime #select
newKey.value = Val
)
)

rollout rlVisibilityTrack "Visibility Track"
(
button btnVisOff "On" width:70 height:30 pos:[5,5]
button btnVisOn "Off" width:70 height:30 pos:[75,5]
button btnDelVisKey "Delete Visibility Key" width:140 height:30 pos:[5,40]

on btnVisOff pressed do
(
if selection.count >= 1 then
(
undo on
(
for obj in selection do
(
if (obj.visibility != bezier_float()) then --Add Visibility Track
(
obj.visibility = bezier_float()
)
fnAddVisKey obj 0.0
)
)
print ("Keys" + " " + sliderTime as string)
)
)
)
createDialog rlVisibilityTrack 150 75
)

Comments (2)

Awe

JokerMartini · 2011-04-01

Thanks Anubis,
I was overlooking that completely.
Thank you for the tips.
I usually try and make sure I do If/Then or If/Do statements as needed.
But thanks again.

JokerMartini

quick catch

Anubis · 2011-03-31

that boolean expression is wrong:

if (obj.visibility != bezier_float()) then

-- it always return True and that replace the controller permanently.

Also (at least in my Max) I use If/Do (when not need Else)
'cause If/Then without Else almost never executes (here).

So, this s'd be fine:

if classOf obj[1].track != bezier_float do obj.visibility = bezier_float()

...and just a tip: not need

with animate on

for addNewKey().