Ignore unassigned materials

I was playing around with a some maxscript and thought I would try and print the name of all the scene materials. I use the code below

for i in scenematerials do
print i.name

The problem is it still prints material names that were assigned at some point but have since been swapped out for another material. I don't mind keeping unused materials in the material editor should I change my mind, but I just wanted to print the materials which are currently assigned in the scene.

Does anyone know of a way around this?

Many Thanks

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ce89's picture

Barigazy, I tried the first

Barigazy,

I tried the first function which worked great.

In terms of the second utility, I forgot to mention I was using the Slate editor. Also i'm not sure if they all need to be "locally in the slate editor" i.e using the picker tool if not present?

It seems a shame it is not possible to access the Scene Materials dialogue list (in the slate editor, left hand side panel) as this only list's the currently assigned materials.

Anyway many thanks for your help, much appreciated!

barigazy's picture

...

U need to refresh scene materials first to print all used materials.
Try this function

fn printSceneMaterials =
(
	--update scene materials first
	tmpFile = (getdir #export + "\del.max")
	saveNodes #() tmpFile
	deleteFile tmpFile
        --print scene materials
	for m in scenematerials do print m
)

Also there is utility function to check used materials.

--check material editor used materials
for m in meditMaterials where MeditUtilities.isMaterialInUse m do print m

bga

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.