MAXscript UI doesn't update to show items added to listbox

Using MAX 2024. If I add an item to a listbox it does not appear in the UI, however the listbox properties say it is there. I’ve tried opening and closing the rollout to see if that would force a refresh, didn’t work. Below is a sample script showing the problem. Any ideas?

utility listboxTest "Listbox Test"
(
	listbox lbxList "Items" items:#("Appears")

	on listboxTest open do
	(
		append lbxList.items "WillNotAppear"
		format "There are [%] items\n" lbxList.items.count -- Returns 2, but still only 1 item appears in the UI
	)
)

Been a hot minute since I used MXS
I was going to point you to an old bookmarked CG talk thread on Struct based UI tool scoping
But it turns out CG Talk shut down this month :frowning:

All I have is this example


/* 
	DennisT's example of a Max Script Struct based tool, correctly scoped as global
	
	source CG talk thread:
	https://forums.cgsociety.org/t/avoiding-multiple-dialog-copies-in-a-struct-tool/1639975/2


*/


global TheTool 
(
	struct ToolStruct 
	(
		dialog = rollout dialog "Dialog"
		(
			local owner = if owner != undefined do owner
			label info_lb align:#center
			on dialog open do info_lb.text = timestamp() as string  
		),

		fn destroy = try(destroydialog TheTool.dialog) catch(),

		fn show =
		(
			destroy()
			createdialog dialog
		),

		on create do 
		(
			destroy()
			dialog.owner = this
		)

	)
	TheTool = ToolStruct()

	ok
)
TheTool.show()

I suspect " opening and closing the rollout " isn’t clearing it from the RAM, it still exists in the initialized state; which is what the destroy fn takes care of in the above case. Perhaps you can mutate this into what you need…

Yeah, so much knowledge lost with the CG forums shut down. :frowning: I was able to figure out the “problem” - MAXscript only triggers a refresh when the assignment operator is used. The code below works. It wasn’t a scoping problem, the original problem happens on a fresh start of MAX with the first invocation of the script.

utility listboxTest "Listbox Test"
(
	listbox lbxList "Items" items:#("Appears")

	on listboxTest open do
	(
		-- Below Line Doesn't work
		-- append lbxList.items "WillNotAppear"
		tempList = lbxList.items
		append tempList "NowThisOneAppears"
		lbxList.items = tempList
	)
)
lbxList.items = append lbxList.items "WillNotAppear"
1 Like

Ha, yeah that’s even cleaner, thank you! I’d forgotten that ‘append’ returns something.

On a side note, we may have lost the CG forums but my goodness we appeared to have gained denisT! I don’t know when else I’ll get this opportunity but you have been helping with my headaches for years, I’m very happy to see you’re here.

I spoke his name and he showed up!
@denisT.MaxDoctor glad to see you’re still sharing your knowledge
You helped me a lot ~10 years ago in my Max days, so thanks