[Closed] Question: find selected objects selection set or sets?
Is there a fast way to find the selection sets that have a selected object in them? I have a scene that has thousands of objects each in various groups of selection sets. I want to be able to pick an object in the scene (its an x-ref btw) and have maxscript find all the selection sets that contain that object. I want to be able to copy that object and put that copy into the previously found selection sets. Many thanks
You could simply iterate over sets and see if it contains the node. See if that works for xrefs
for obj in selection collect
(
sets_containing_object = for selset in selectionsets where finditem selset obj > 0 collect selset
DataPair obj:obj sets:sets_containing_object
)
That works a charm – quick question using the found selection sets how would I put a copy of that object into those selection sets? Thanks again.
just google it “maxscript add to selection set”
there’re lots of threads with examples
ok I think I figured it – probably not the most elegant code but seems to work fine. Thanks again.
thePair = #()
copyObjsSel = #()
for obj in selection collect
(
sets_containing_object = for selset in selectionsets where finditem selset obj > 0 collect selset
thePair = DataPair obj:obj sets:sets_containing_object
copyObj = copy thePair.v1
append copyObjsSel copyObj
for loopSets = 1 to thePair.v2.count do
(
currentSelSetName = thePair.v2[loopSets].name
selectionsets[currentSelSetName] = join (join #() selectionsets[currentSelSetName]) copyObj
)
)
select copyObjsSel
you’d better to use clone nodes
nodes_of_selection_set = join #() selectionsets[ sel_set_name ] -- retreive nodes for sel set
if maxOps.CloneNodes (selection as array) cloneType:#instance newnodes:&new_nodes do -- try to clone selection
(
selectionsets[ sel_set_name ] = join nodes_of_selection_set new_nodes -- combine them together and put into sel set
)
ok I’ll give it a go. I’m not sure the distinction between copy and clone. Does clone have advantages over copy? Cheers