How to exclude instances from a selection?

How to exclude instances from a selection?

Anonymous
Not applicable
578 Views
5 Replies
Message 1 of 6

How to exclude instances from a selection?

Anonymous
Not applicable
Need some help...

I have a whole heap of objects (some instances) and want to create a new array of all the objects except the instances.

This is my attempt, but can't get it to work?

ss = getCurrentSelection()
newSS = #() -- the new array
append newSS ss --put the first object in it

for i = 2 to ss.count do -- go through all the object I have selected
(
thecurrentNode = ss -- the selected node
for j = 1 to newSS.count do -- go through the new array
(
theArrayNode = newSS -- get the object from the new array
if (areNodesInstances thecurrentNode theArrayNode) == false then -- check if the selected node is an instance of the new array node
(
if (finditem newSS thecurrentNode) == 0 then -- check that selected node isn't already in the array
(
append newSS thecurrentNode -- add the selected node to the new array
print ("not instance = " + thecurrentNode.name)
)
)
)
)


Thanks
0 Likes
579 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
Ok, got it to work. Could trim it down a fair bit...but at least its working:


ss = getCurrentSelection()
newSS = #() -- the new array
for i = 1 to ss.count do -- go through all the object I have selected
(
thecurrentNode = ss -- the selected node
check = "Not in Array"
for j = 1 to newSS.count do -- go through the new array
(
theArrayNode = newSS -- get the object from the new array
if (areNodesInstances theArrayNode thecurrentNode) == true then check = "Is in Array"-- check if the selected node is an instance of the new array node
)
if check == "Not in Array" then
(
append newSS thecurrentNode -- add the selected node to the new array
print ("not instance = " + thecurrentNode.name)
)
)
0 Likes
Message 3 of 6

Anonymous
Not applicable
Also check out this pack...

http://www.neilblevins.com/soulburnscripts/soulburnscripts.htm

There's a script called sLib.ms that contains a function called sLibRemoveUnneededInstancesFromArray which will probably do what you need.

- Neil
0 Likes
Message 4 of 6

Anonymous
Not applicable
Thanks Neil.
0 Likes
Message 5 of 6

Anonymous
Not applicable
There is another way to do this that I use in my own tools. It takes advantage of the Instance Manager in a hackish sort of way but is quite simple:


-- Selects all objects that have no instances

myObjs = selection as array

clearSelection()

for o in myObjs do
(
InstanceMgr.GetInstances o &instances
if instances.count == 1 then selectmore instances
)


The reason this works is because InstanceMgr.GetInstances returns an array of only the current object even if it has no other instances. If the array size is 1 the object has no instances. If the array size is more than 1 the last object in the array can usually be considered the "original" object (even though it doesn't seem there is a way to keep track of this in the GUI).

Hope this helps!
0 Likes
Message 6 of 6

Anonymous
Not applicable
Very smart way of doing it. I initally looked at the instanceManager and couldn't work out a way to use it for what I wanted, so went back to basics (very basic):)
Thanks for explaining

Cheers
0 Likes