ScriptSpot

Forum topic · General Scripting

multilist (add if new obj)

By JokerMartini · 2011-05-16

Description

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 (5)

miauu · 2011-05-17

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. :)

You don't have to specify the object name.

JokerMartini · 2011-05-17

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

JokerMartini · 2011-05-17

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

br0t · 2011-05-17

Hey John,

look for

appendIfUnique

in the help file, guess that could work for you

Cheers

McGreed · 2011-05-17

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"
)