How to Add Remove objects for SelectionSet


#1

Hey

im Trying to figure out how to Add/Remove Objects for a SelectionSet ,
i found this post

https://forums.autodesk.com/t5/3ds-max-programming/append-items-in-selectionsets/td-p/4214435

but i cant make it work

there is two ways that they try to make it

oldStuff = selection --store current selection if necessary
myStuff = selectionsSets
selectMore myStuff
selectionsSets = selection
select oldStuff --if necessary

and

selectionsets = join (for n in selectionsets collect n) thenodes

lets say i have a selectionSet called Characters and i want to Add Teapot001 to the SelectionSet - how would i do that .

thanks
D.


#2

selectionSets[#Characters] = ((for o in selectionSets[#Characters] collect o) + #($Teapot001))


#3

thanks :slight_smile:

and what if i want to remove an object ?


#4

selectionSets[#Characters] = deleteItem (for o in selectionSets[#Characters] collect o) (findItem (for o in selectionSets[#Characters] collect o) $Teapot001)


#5

if need more efficiency , use bwlow

nodearray = for o in selectionSets[#Characters] collect o
selectionSets[#Characters] = deleteItem nodearray (findItem nodearray $Teapot001)

#6

i already showed the ‘nice’ selection set routine methods on this forum but can do it again:

-- all selection sets as array:
sets = join #() selectionsets

-- all nodes in selection set by name:
nodes = join #() selectionsets[#a]

-- all nodes in selection set by index:
nodes = join #() selectionsets[1]


-- add <nodes> (or node collection) to selection set
selectionsets[#a] = join (join #() selectionsets[#a]) <nodes>

-- remove <node> from selection set:
selectionsets[#a] = for n in selectionsets[#a] where n != <node> collect n