Notifications
Clear all

[Closed] Maxscript listbox help

Hey,

How can i check to see if the object name im adding to the listbox is already in the box?
Im collecting cad blocks into a listbox but i only want one of each object and there are hundreds of instances at the moment.

Any ideas?
Thanks
Jack

3 Replies

If you need to check just for the objects names, you can use something like this:

(
	try (destroydialog ::RO_TEST)catch()
	rollout RO_TEST "" width:208 height:248
	(
		listBox lbx1 "Objects:" pos:[8,8] width:192 height:13
		button  bt_add "Add Selected" pos:[8,208] width:192 height:32
		
		on bt_add pressed do
		(
			items = lbx1.items
			for j in selection do appendifunique items j.name
			lbx1.items = sort items
		)
	)
	createdialog RO_TEST
)

(
	local exampleArrayOfStrings = #("Test", "Test", "test", "teSt", "tEsT", "test", "TEST")
	
	-- this is a character sensitive method:
	local uniqueArrayOfStrings1 = makeUniqueArray exampleArrayOfStrings
	
	-- this is NOT a character sensitive method:
	local usedItemNames = #()
	local uniqueArrayOfStrings2 = #()
	
	for item in exampleArrayOfStrings do (
		local itemName = item as Name
		
		if findItem usedItemNames itemName == 0 then (
			append usedItemNames itemName
			append uniqueArrayOfStrings2 item
		)
	)
	
	format "method1: %
" uniqueArrayOfStrings1
	format "method2: %
" uniqueArrayOfStrings2
)

that worked great thanks!

  • J