|
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[1] --put the first object in it
for i = 2 to ss.count do -- go through all the object I have selected
(
thecurrentNode = ss[i] -- the selected node
for j = 1 to newSS.count do -- go through the new array
(
theArrayNode = newSS[j] -- 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
|
|
|
|
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[i] -- the selected node
check = "Not in Array"
for j = 1 to newSS.count do -- go through the new array
(
theArrayNode = newSS[j] -- 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)
)
)
|
|
|
|
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
|
|
|
|
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[instances.count]
)
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!
|
|
|
|
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
|
|
|