Notifications
Clear all

[Closed] Change property of material on multiple objects

I’ve wrote this little piece of code, but, as I’m a beginner in maxscript, I cannot figure out why it’s not working as I expect.
Basically, if I don’t select anything, it’s working ok, but after the “else” part, specular is not controlling the selected materials of my scene. Hints?

(
rollout ssp “Standard materials” –assign a name to the rollout

(
spinner spnspec “Specular” range:[0,100,0] type:#integer –draw the spinner
on spnspec changed val do –read the values
if (selection.count == 0) –if nothing is selected
then for mat in scenematerials do –then change the specular for all materials
mat.specularlevel = val
else for obj in selection do
$.material = mat
mat.specularlevel = val
)
createdialog ssp –draw the dialog
)

4 Replies

I think you’re just missing a few brackets… and got one line wrong…


(
rollout ssp "Standard materials" --assign a name to the rollout
(
spinner spnspec "Specular" range:[0,100,0] type:#integer --draw the spinner

on spnspec changed val do --read the values
(
if (selection.count == 0) then  --if nothing is selected
(
for mat in scenematerials do --then change the specular for all materials
mat.specularlevel = val
)
else 
(
for obj in selection do
(
$.material.specularlevel = val
)
)
)
createdialog ssp --draw the dialog
)

P.S. take a look at my blog if you’re learning maxscript, covers this sort of simple setup quite clearly.

i would also modify the following:

else
(
for obj in selection do
(
$.material.specularlevel = val
)

to this:

else
(
for obj in selection do
(
obj.material.specularlevel = val
)

Oops yep Matt is absolutely correct there.

Thanks guys. Works perfect