Call for Submission
NAB 2012 Best of the Best Show Reel
Submit your work today!
  • 1/3
You are here: Forum Home / Autodesk 3ds® Max® / MaxScript / How to exclude instances from a selection?
  RSS 2.0 ATOM  

How to exclude instances from a selection?
Rate this thread
 
36222
 
Permlink of this thread   Subscribe to this thread
avatar
  • bobcat
  • Posted: 01 November 2009 11:22 AM
  • Total Posts: 20
  • Joined: 23 August 2006 06:23 PM

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 2 to ss.count do -- go through all the object I have selected
(
 thecurrentNode 
ss[i] -- the selected node
 
for 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



Replies: 0
avatar
  • bobcat
  • Posted: 01 November 2009 05:44 PM

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

ss getCurrentSelection()
newSS 
#() -- the new array
for 1 to ss.count do -- go through all the object I have selected
(
 thecurrentNode 
ss[i] -- the selected node
 check 
"Not in Array"
 
for 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)
 )
)


Replies: 0
avatar
  • soulburn
  • Posted: 02 November 2009 06:39 AM

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



Replies: 0
avatar
  • bobcat
  • Posted: 02 November 2009 02:14 PM

Thanks Neil.



Replies: 0
avatar
  • ma3stro
  • Posted: 16 November 2009 06:49 AM

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!



Replies: 0
avatar
  • bobcat
  • Posted: 17 November 2009 02:34 PM

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



Replies: 0




   
  Settings Choose Theme color: