PDA

View Full Version : Quick Question Apply material with max script?


Patan77
11-04-2011, 04:15 PM
Hi how do I apply a material to an object with max script?

I have a radio button with two options when its set to option 1 it assigns one material and when it is set to option 2 it assign another material.

This is what i have now and it doesn't work to good, because if I have material 1 applied to the object then i click option 2 it assigns an undefined material then if i click option 1 it assigns material 1, and the same things happens but in the opposite way if i have material 2 applied from the beginning.

CODE:
http://www.patan77.com/help/27.JPG


MATERIAL:
http://www.patan77.com/help/28.JPG

thanks in advance (:

Pjanssen
11-04-2011, 05:12 PM
The assignment code itself looks fine. However, I suspect your issue might lie in the "if logo03 == 3 then" part. What's logo03? And why do you compare it to 3 for a radiobutton with 2 options? Shouldn't you be comparing i to 1 or 2 instead?

Patan77
11-04-2011, 05:44 PM
The assignment code itself looks fine. However, I suspect your issue might lie in the "if logo03 == 3 then" part. What's logo03? And why do you compare it to 3 for a radiobutton with 2 options? Shouldn't you be comparing i to 1 or 2 instead?

logo03 is just the name but when I checks the value of the radio button in the max listener i get the value 2 when on and the value 3 when off. Don't know why it isn't 1 and 2

http://www.patan77.com/help/29.JPG

http://www.patan77.com/help/30.JPG

Pjanssen
11-04-2011, 06:41 PM
Well it is nigh-impossible to debug code from just those 10 lines. As I said, the material assignment statements seem fine, so it is probably a problem in the if statement, if it is in this section of the code at all. You should probably introduce some print statements to see what kind of branching happens.
And to be on the safe side, wrap your radiobutton changed handler code in parentheses.

Patan77
11-04-2011, 07:24 PM
Well it is nigh-impossible to debug code from just those 10 lines. As I said, the material assignment statements seem fine, so it is probably a problem in the if statement, if it is in this section of the code at all. You should probably introduce some print statements to see what kind of branching happens.
And to be on the safe side, wrap your radiobutton changed handler code in parentheses.

The whole current code(open in new window/tab):
http://www.patan77.com/help/40.png

if I add messagebox"on" and "off" then the if statement seams to work fine.

VIDEO [720p](1mb):
www.patan77.com/video/if_script.mp4

http://www.patan77.com/help/31.JPG

Pjanssen
11-04-2011, 07:28 PM
Hm, this is a bit of a guess, but could it be that "head_no_logo" isn't actually in the scenematerials array because it is a submaterial? Try executing just that and see if it returns undefined.

PiXeL_MoNKeY
11-04-2011, 08:44 PM
You may try collecting the material classes into an array and filtering by name. Something like:vMtlArr = getClassInstances VrayMtl
hNoLogo = (for vMat in vMtlArr where vMat.name == "head_no_logo" collect vMat)[1]That will assign the first Vray Mtl with the name "head_no_logo" to the hNoLogo variable.

-Eric

Patan77
11-04-2011, 09:58 PM
You may try collecting the material classes into an array and filtering by name. Something like:vMtlArr = getClassInstances VrayMtl
hNoLogo = (for vMat in vMtlArr where vMat.name == "head_no_logo" collect vMat)[1]That will assign the first Vray Mtl with the name "head_no_logo" to the hNoLogo variable.

-Eric

Hi sorry for the noob question but how should I implement that in my code?^^

(btw I'm very new to max script and this is my first script that I'm trying to do )

This is what I tried but I guess this is wrong way?

http://www.patan77.com/help/32.JPG

Something very strange happened when i did that^^ my bitmap in the menu is visible now, that's so random, don't get it, its way to dark but now it's at least showing.

http://www.patan77.com/help/33.JPG

PiXeL_MoNKeY
11-04-2011, 10:19 PM
Anywhere you have scenematerials["head_no_logo"] change to hNoLogo
replace:$head_.material = scenematerials["head_no_logo"]
with:$head_.material = hNoLogo

-Eric

Patan77
11-05-2011, 12:20 AM
Anywhere you have scenematerials["head_no_logo"] change to hNoLogo
replace:$head_.material = scenematerials["head_no_logo"]
with:$head_.material = hNoLogo

-Eric

Yes it works now, thank you :D

EDIT:

Now the off (no logo works) I guess I need to do the same for the on option (with logo). I still don't really understand that thing with the array, but how should I do for the on option?

http://www.patan77.com/help/34.JPG

Patan77
11-08-2011, 05:14 PM
I have solved it now, the problem with my other material was that i were a VrayBlendMtl

http://www.patan77.com/help/35.JPG

CGTalk Moderation
11-08-2011, 05:14 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.