[Closed] Quick Question Apply material with max script?
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:
MATERIAL:
thanks in advance (:
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
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.
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.
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?
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.
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
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?
I have solved it now, the problem with my other material was that i were a VrayBlendMtl