ScriptSpot

Forum topic · General Scripting

Populating dropdownlist

By JokerMartini · 2011-05-26

Description

I need to populate a dropdown list with all the scene cameras. Which that part is simple.
But the problem I'm coming across is if someone creates a camera after the dialog has been opened. What do you guys thing would be the best way to re-populate the dialog?

My first thought is a selection callback function.

Here is the base of the script so far.


(
camArray = for i in cameras where superclassof i == Camera collect i.name

rollout drop_roll "Drop Down List"
(
dropdownlist obj_dd "Objects :" offset:[0,-20] items:camArray
)
createDialog drop_roll
)

Comments (4)

Alright

JokerMartini · 2011-05-26

Thanks Anubis, I'll be sure to look into using this instead of the callback I was using before.

just a tip

Anubis · 2011-05-26

Goin in that way (using the General Event Callback Mechanism)
you should add more callbacks:

#nodeCloned

- to catch cloned objects too

#sceneNodeAdded

- to catch merged objects

In the new NodeEventCallback (added in Max 2009)
you can do this with 1 callback,
and its more precise - catch even undo/redo operations.

-- shortly...
rollout foo "..."
(
	local callbackItem
	fn cbFn ev nd = ( ... )
	
	-- ...
	
	on foo open do (
		callbackItem = NodeEventCallback mouseUp:true \
		delay:1000 added:cbFn deleted:cbFn
	)
	on foo close do (
		callbackItem = undefined
		gc light:true
	)
)

callback on node create

JokerMartini · 2011-05-26

Not sure why this isn't working..
Once i get this working I'll add a nodeDeleted callback as well.


(
global drop_roll

camArray = for i in cameras where superclassof i == Camera collect i.name

rollout drop_roll "Drop Down List"
(
dropdownlist obj_dd "Objects :" offset:[0,-20] items:camArray

fn fnUpdateCamList =
(
print "cool"
camArray = for i in cameras where superclassof i == Camera collect i.name
drop_roll.obj_dd.items = camArray
)
)

on drop_roll close do (callbacks.RemoveScripts #nodeCreated id:#camUpdate)

on drop_roll open do
(
callbacks.addScript #nodeCreated "drop_roll.fnUpdateCamList()" id:#camUpdate
)

createDialog drop_roll
)

JokerMartini · 2011-05-26

Got it. The rollout () were wrong.