visibility key problem

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

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
JokerMartini's picture

Awe

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

John Martini
Digital Artist
http://www.JokerMartini.com (new site)

Anubis's picture

quick catch

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().

my recent MAXScripts RSS (archive here)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.