View Full Version : Selecting ONLY materials in a scene

03 March 2008, 01:11 PM
I'm writing a little script to perform various operations on all the materials used in my scene at once.
I use the scenematerials global to return the number of materials used and loop through them. But the problem is that it also returns the maps used. How can I select only the materials ?

03 March 2008, 01:22 PM
Unless there's another command that I don't know, you could just do a collect:

materials = for m in scenematerials where superclassof m == material collect m

I'm not sure if "material" is the right superclass to test against right now, but you get the idea.

Also not sure if scenematerials holds references to ALL the materials, or just the top-level materials. You would have to check.

I'm not in front of max right now, so I can't be 100% of the validity of this advice this second! ;)

03 March 2008, 02:01 PM
Also bare in mind that the scenematerials array is only update when opening a file, saving a file or adding a new material instance to the scene (if I remember correctly). So for example removing a material from the scene will cause no update and therefore the amterial will still show up on the scenematerials array.

03 March 2008, 02:22 PM
Thanks a lot davestewart ! That was it. Now it works fine

@MarcoBrunetta : Didn't know that, and it is not mentioned in the help file ! I'll have to keep it in mind. Thank you.

03 March 2008, 02:32 PM
Go here...

And get the latest collection. It includes a file called sLib, which contains much better code for collecting scene materials. Feel free to use it in your script.

- Neil

03 March 2008, 03:03 PM
That's cool Neil ! Thank you

CGTalk Moderation
03 March 2008, 03:03 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.