Maxscript: selfIllumAmount

I have a very basic problem. I have a very large scene, with plenty of materials, and I’m trying to change the selfillumination amount all at once.

I came across a thread that appears to be what I need:

(
if hasProperty s “selfIllumAmount” then
s.selfIllumAmount = amount
else if classof s == multiMaterial then
for m in s where hasProperty m “selfIllumAmount” do
m.selfIllumAmount = amount
)

source thread

When I try to interpret it and input amounts, I receive a syntax error that is expecting <factor> at ).

When accessing the help file for <factor>, it brings me to the help file home screen.

Is “s” a variable that I had to define? Probably my main problem is that I don’t fully understand what the block is trying to achieve. I understand that it’s testing to see if the self illum property exists, and if it does, set it to the desired percent. I’m under the impression that the second part states that if “s” is a multimat then test the materials inside “s” and change their self illum amount!

Am I way off there?

Judging by the seeming complexity of the other threads in this section, this post seems a little unworthy, but I figure I’d take a shot.

I’m just beginning to learn maxscript, and am at the point that I recognize where a simple little script would be more efficient, but am unable to achieve the result, and spend my time fumbling around in syntax.

I’m currently working through the John Wainwright video tutorials.

Thanks for taking the time to read this over, and I appreciate any input you folks may have!

works for me if s and amount are defined:


(
    amount = 10
    for s in meditmaterials do
        if hasProperty s "selfIllumAmount" then
            s.selfIllumAmount = amount
        else if classof s == multiMaterial then
            for m in s where hasProperty m "selfIllumAmount" do
                m.selfIllumAmount = amount
)

this will process all materials in the material editor.
with scenematerials you can access all materials in the current scene.

edit: looking at the source-thread, it looks like you missed the first line - he already loops through all scenematerials :slight_smile:

Hey Sascha, your edit was absolutely right, I missed it!

Note to self: Always view original formatting on cgtalk threads! That was definitely an instance where I needed to pay closer attention. I mistook that first bit for part of the preceding paragraph!

The amount definition and the start of the for loop makes this read a lot easier for me :slight_smile: go figure! One little question, if you have a little more time: you said it worked if s and amount were defined. Can you point out where it is defined? I can spot the straight forward x = “blahblah” code, but I don’t see that for s.

I tested it out on a temp scene and got the desired results. This little script is a keeper. I can imagine all sorts of great variations to use.

Thank you very much for the help.

[QUOTE=Emericanized;11022]Can you point out where it is defined? I can spot the straight forward x = “blahblah” code, but I don’t see that for s.
[/QUOTE]

It’s coming from the first loop:

for s in meditmaterials do

This will loop through all elements in the array and for each iteration make ‘s’ point at the current element.
Very handy! I suggest you read the for loop documentation in the maxscript help for more tricks.

You can even do things like:


a = for m in scenematerials where classof m == multimaterial collect m

This will put all the multimaterials in the scene into an array.
Powerful stuff. :wink:

I’m trying this code but i get a different result. Im probably overlooking something since this is my first max-script:

utility StairCase "demoTools_MaterialOperations"
(

	button btnCreate "Change Materials"

	on btnCreate pressed  do(
    amount = 10
    for s in meditmaterials do
        if hasProperty s "selfIllumAmount" then
            s.selfIllumAmount = amount
        else if classof s == multiMaterial then
            for m in s where hasProperty m "selfIllumAmount" do
                m.selfIllumAmount = amount
)
)

Using max 2011 student edition.

error is:
>> MAXScript Rollout Handler Exception: – No ““showProperties”” function for undefined <<

Help much appreciated

Erwin, the error your getting doesn’t appear to be in the code you posted?

Yes i found that strange myself. But after restarting 3Ds Max i noticed it loaded different code then i thought it did. Which is probably why my changes in the code had no effect either. Meanwhile I’ve taken a different road:

utility materialsChange "demoTools_MaterialOperations"
(

	button btnCreate "Change Materials"

on btnCreate pressed  do(
	
		material_array = for m in scenematerials where classof m == multimaterial collect m
		
        for i = 1 to material_array.count do(
            material_array[i].useSelfIllumColor = on
			material_array[i].selfIllumColor = color 255 255 255
        )
    )
)

This gives me:
>> MAXScript Rollout Handler Exception: – Unknown property: “count” in 10 <<

I think it’s because material_array isn’t an array because my forloop from the example isn’t implemented properly. What do you guys think?

I’m pretty sure you can’t use scenematerials directly, you have to say ‘for i in 1 to scenematerials.count collect scenematerials[i]’

This should do it:

(
	fn setIllumAmount materials amount =
	(
		for i in materials do
		(
			case (classof i) of
			(
				(Multimaterial):
				(
					for j = 1 to i.numsubs do
					(
						if (hasProperty i[j] "selfIllumAmount") then i[j].selfIllumAmount = amount
					)
				)
				default:if (hasProperty i "selfIllumAmount") then i.selfIllumAmount = amount
			)
		)
	)
	setIllumAmount scenematerials 100
)