Multilistbox problem


#1

Hi
Problem with multilistbox

(
 	local MYObjs = #()
 	rollout multi "" height:245 	width:140
 	(
 		multiListBox lbx_Obj "Objects list" pos:[10,7] width:120 height:12
 		button Add_Obj  "Add" pos:[10,185] width:24 height:24
 		button sel_lis "sel" pos:[34,185] width:24 height:24
 		button Mov_Up_lis "^" pos:[82,185] width:24 height:24
 		button Mov_Dw_lis "v" pos:[106,185] width:24 height:24
 		
 
 --add objects to the multiListBox		
 		on Add_Obj  pressed do 
 		(
 			userSel = getCurrentSelection()
 			if userSel.count >= 1 do
 			(
 				 for o in userSel do (appendIfUnique MYObjs o)
 				lbx_Obj.items = for i in MYObjs collect i.name -- update list with array
 			)
 		)		
 --select all scene objects	in multilistbox items
 		on lbx_Obj selected lis do
 		(
 			itemsel = for j in lbx_Obj.selection collect getnodebyname lbx_Obj.items[j]
 			select itemsel
 		)	
 		
 		on Mov_Up_lis pressed do 
 		( 
 				local itm = lbx_Obj.selection as array				
 				swap lbx_Obj.items[itm] lbx_Obj.items[itm-1]
 				lbx_Obj.items = lbx_Obj.items
 				swap AnimObjs[itm] AnimObjs[itm-1]
 				lbx_Obj.selection -= 1							
 		)
 		
 		on Mov_Dw_lis pressed do 
 		(
 			local itm = lbx_Obj.selection
 			if itm < lbx_Obj.items.count do 
 			(
 				swap lbx_Obj.items[itm] lbx_Obj.items[itm+1]
 				lbx_Obj.items = lbx_Obj.items
 				swap MYObjs[itm] MYObjs[itm+1]
 				lbx_Obj.selection += 1
 			)
 		)
 	)
 	createDialog multi 
 )

1_we adds some objects to the multilistbox list, is it possible by a button or function when we select the objects in the scene the objects get selected in the multilistbox list?

2_can anyone help me with the shifting the multi listbox items

Thanks in advance


Selection in viewport updates the selection in multilistbox
#2
try(destroydialog ::ro_multilist)catch()
 
 rollout ro_multilist "" width:168 height:224
 (
 	multiListBox lbx_objects "Objects:" pos:[8,7] width:152 height:12
 	button bt_add "+" pos:[8,192] width:24 height:24
 	button bt_delete "-" pos:[32,192] width:24 height:24
 	button bt_moveUp "Up" pos:[80,192] width:40 height:24
 	button bt_moveDown "Down" pos:[120,192] width:40 height:24
 	
 	fn SelectionChanged =
 	(
 		lbx_objects.selection = for j in selection collect finditem lbx_objects.items j.name
 	)
 	
 	fn AddNodes ctrl =
 	(
 		ctrl.items = makeuniquearray (ctrl.items + (for j in selection collect j.name))
 	)
 	
 	fn DeleteNodes ctrl =
 	(
 		if not ctrl.selection.isEmpty do
 		(
 			ctrl.items = for j = 1 to ctrl.items.count where not ctrl.selection[j] collect ctrl.items[j]
 			clearselection()
 			for j in ctrl.selection do select (getnodebyname ctrl.items[j])
 		)
 	)
 	
 	fn MoveItem ctrl dir:1 =
 	(
 		if ctrl.selection.numberset == 1 do
 		(
 			local arr = ctrl.items
 			sel = (ctrl.selection as array)[1]
 			
 			if case dir of
 			(
 				(-1):sel > 1
 				( 1):sel < arr.count
 			)
 			do
 			(
 				swap arr[sel] arr[sel+dir]
 				ctrl.items = arr
 				ctrl.selection = sel+dir
 			)
 		)
 	)
 
 	on ro_multilist open do
 	(
 		callbacks.removescripts id:#ID0X7FB0F2910X78FF0B50
 		callbacks.addscript #selectionSetChanged "ro_multilist.SelectionChanged()" id:#ID0X7FB0F2910X78FF0B50
 	)
 	
 	on ro_multilist close do
 	(
 		callbacks.removescripts id:#ID0X7FB0F2910X78FF0B50
 		ro_multilist=()
 	)
 
 	on bt_add pressed do AddNodes lbx_objects
 	
 	on bt_delete pressed do DeleteNodes lbx_objects
 	
 	on bt_moveUp pressed do MoveItem lbx_objects dir:-1
 		
 	on bt_moveDown pressed do MoveItem lbx_objects dir:1
 
 	on lbx_objects selected arg do
 	(
 		select (for j in lbx_objects.selection collect getnodebyname lbx_objects.items[j])
 	)
 
 )
 
 createDialog ro_multilist

It needs optimizations.


#3

Thanks so much Jorge
I’ve never could do this with my awful scripting

Thanks again man


#4

I’d say in addition to loading the callback on opening the rollout, try to unregister it first. I know you doing it on the close, but this will be a fail safe. You can even list the current callbacks in the scene on opening the rollout then unregister if found.


#5

In the previous sample script the Callback is being unregistered on both Open and Close events, or are you suggesting something different?

Additionally, while it might be a good practice, from my experience I don’t find it is really necessary to check if a given Callback already exist in order to remove it, as removeScripts() won’t throw any exception if the Callback doesn’t exist.