Notifications
Clear all

[Closed] Selecting ONLY materials in a scene

Hello,
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 ?
Thanks

5 Replies

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!

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.

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.

Go here…

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

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

That’s cool Neil ! Thank you