object/material list

Hello

I wanted to print in maxlistener the list of selected objects with their material name. (to check my scene)
Problem is that I want to make a script to sort by name and print objects with their material :
box 1 // wood
box 2 // glass
box 3 // metal
and another to sort by material with object name.
glass // box 2
metal // box 3
wood // box 1

my problem is when I sort object names I can't figure how to associate material name to b.name....

-----------------------------------------
sel = for b in selection collect b.name
sort sel
for o in sel do
(
print ( "___" + o + "material name")
)
------------------------------------------

If somebody can help.... :-))

Comments

Comment viewing options

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

In place of

In place of "i.material.name" I prefer "i.material as string", so Max print material description too. :-)

titane357's picture

Thanks for help Marco and

Thanks for help Marco and Anubis !!! :-))

Anubis's picture

There is some idea from me.

There is some idea from me. Maybe not perfect but easy to understand (i hope):

sel = selection as array
arrObjMtl = #()
arrMtlObj = #()
for i in sel do
(
	if i.material != undefined then (
		append arrObjMtl (i.name + " :: " + i.material.name)
		append arrMtlObj (i.material.name + " :: " + i.name)
	)
	else (
		append arrObjMtl (i.name + " :: " + "--")
		append arrMtlObj ("--" + " :: " + i.name)
	)
)
sort arrObjMtl ; sort arrMtlObj
for i in arrObjMtl do print i
for i in arrMtlObj do print i

P.S. - check for materials is important!

my recent MAXScripts RSS (archive here)

Marco Brunetta's picture

A quick and dirty solution

A quick and dirty solution could be something like:

(
sel = for b in selection collect b.name
sort sel
for o in sel do
(
print ( "___" + o +" material:"+ (execute ("$"+o+".material.name")))
)
)

However it's not really "nice" specially because it's using execute. If you are trying to develop this for something a bit more professional then you should consider creating a custom sorting function using qsort.

Comment viewing options

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