PDA

View Full Version : Select by material


chriskroll
02-15-2008, 05:21 PM
How can I select all objects in a scene that have a common scene material applied to them?

j-man
02-15-2008, 05:29 PM
yikes!

well ok, what you need to do is to iterate through all the objects in the scene to see what material they have :


obj=selection[1] -- the first selected object, in this case the source material
sel=#() -- and empty array to hold the results
for o in objects do -- iterate through all the objects
(
if o.material==obj.material then append sel o -- test the material
)
select sel -- select the results < :


is there an easier way ??

Hope that helps.

J.

chriskroll
02-15-2008, 06:14 PM
I was hoping there was a built in function, but this code should be fast enough. Thanks for the help.

Kramsurfer
02-15-2008, 06:45 PM
A bit faster... if you're suffering from an huge scene file...


select (for SelObj in objects where SelObj.material == Selection[1].material collect SelObj)

j-man
02-15-2008, 11:38 PM
ah keith, faster? yes? but prettier? no.

< :

J.

Alex Morris
02-18-2008, 05:50 PM
have a look at:


ra = refs.dependents mat
ro = for i in ra where superClassOf i == GeometryClass collect i
selection = ro

this seems to be quicker on my version of max9 (might need tweaking as I can't check the code right now)

Alex

Alex Morris
02-18-2008, 05:51 PM
oh and you'll need to do some checks for multisub, blend etc where materials can be wrapped in other materials...........

scrimski
02-18-2008, 06:09 PM
I was hoping there was a built in function, but this code should be fast enough. Thanks for the help.

You mean like
Select By Material allows you to select objects in the scene, based on the active material in the Material Editor. This button is unavailable unless the active sample slot contains a material used in the scene.

MoonDoggie
02-18-2008, 06:09 PM
There is a built in button. On the material editor look to the middle right side of the pane with some colored spheres, it's one of those buttons. Or, I wrote a script to extend it's functionality to grouped/frozen/hidden objects here

http://www.scriptspot.com/3ds-max/selectobjectsbymaterial

-Colin

Alex Morris
02-19-2008, 12:28 PM
the trouble with the button is that if the material you have selected is also a component of a blend or multisub material then objects with these wrappers also get picked.

MoonDoggie
02-19-2008, 02:52 PM
My script does not have this problem.

CGTalk Moderation
02-19-2008, 02:52 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.