multilist (add if new obj)

I want to add a new object only if its not already in the list. I don't want duplicate names of the same object.
This is what I have so far but I'm not sure what I'm missing? Why wont it work.

(
	try(DestroyDialog rlDitto)catch()
 
	local AnimObjs = #()
 
	rollout rlD ""
	(
		MultiListBox mlbxAnimatedObjects "Animated Objects" pos:[10,7] width:120 height:12
			button btnAddAnimObj "+" pos:[10,185] width:24 height:24
 
		on btnAddAnimObj pressed do
		(
			userSel = getCurrentSelection()
			if userSel.count >= 1 do
			(
 				for o in userSel do
 				(
					for i=1 to mlbxAnimatedObjects.items.count do
					(
						currListObj = (getNodeByName mlbxAnimatedObjects.items[i])
						if (currListObj.name != o.name) do
						(
							append mlbxAnimatedObjects.items o.name
							mlbxAnimatedObjects.items = mlbxAnimatedObjects.items
							append AnimObjs o
						)
					)
				)
			)
			print AnimObjs
		)
	)
	createDialog rlD
)

Comments

Comment viewing options

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

What will happend if you have

What will happend if you have 2 different objects with the same name?

For example(stupid example I think):

Hand_01 - editable poly

Hand_01 - standart primitive

I suggest you to use GetHandleByAnim/ GetAnimByHandle or handle/maxOps.getNodeByHandle  to collect the objects. :)

JokerMartini's picture

You don't have to specify the object name.

It will add it if the object is unique whether the name is the name or not.

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

JokerMartini's picture

Thanks

Thanks guys for the help. I was unaware of the Append if unique. Thanks you very much.

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

br0t's picture

Hey John, look for

Hey John,

look for appendIfUnique in the help file, guess that could work for you

Cheers

Never get low & slow & out of ideas

McGreed's picture

You can use the command

You can use the command findItem

myArray = #("array1", "array2", "array3")
x = findItem myArray.items searchObj.name
if (searchObj != undefined and x == 0) do
(
myArray .items = append myArray .items (searchObj.name as string)
) else (
messageBox "Sorry, this item is already in the list"
)

Comment viewing options

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