Notifications
Clear all

[Closed] How to create a Button that assigns a material

Hello there!
What i want to do is to have a button one one of my toolbars that basically assigns a Default standard gray material to an object that is selected. The material has to be the same everytime I assign it to a new object, so that there is always that same “Default” material that get”s used throught the scene.
I found simillar script here that would assign a material with a name of the object it”s been assigned to – something I don”t want because of tons of materials it would result of in the scene later on.

I got the idea after watching Gnomon DVD called Environment creation with Tim Jones, guy from Blur studio which had this “ModMat” button on his toolbar that would assign simple standard grey material everytime.

Thanks in advance!

5 Replies

i don’t think you need a button if you want it in a toolbar

you can simply put this in the maxscript listener and drag it to your tool bar

$.material = standard () 

it will work as you have a selection
you can do alot more , but i wonder if this is because of colors only
you can simply turn off color randomization when creating objects

this is exactly what I tried – by doing it on different object will result in multiple instances of “Standardmaterial”
what I want is that the script reuses this Standard material from one object to the other.

1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0
macroScript OneDefaultMat category:"CGTalk"
 (
 global OneDefaultMaterial_Definition
 if OneDefaultMaterial_Definition == undefined do OneDefaultMaterial_Definition = standard()
 if selection.count > 0 do selection.material = OneDefaultMaterial_Definition
 )

This defines a global variable called OneDefaultMaterial_Definition
The first time you run the script in a session, that variable would be undefined, in that case it will be populated with a standard material.
If you have selected anything, that materail will be assigned to the selection.

Now if you continue pressing the button, the script will see that the material is not undefined and will not replace it with a new one, so the SAME material will be instanced across all objects you ever use it on.

Of course, if you close Max, restart and load an existing scene, the material you will assign will not be the same anymore. It would be possible to scan the scene for a material with a given unique name if you would name this standard material when assigning, but that might be going too far. If you want that, it is surely possible.

create the material you want and make it in the material slot no. 1

$.material = meditMaterials[1] 

you sure know that you can change the NO. “1” to whatever material slot you want

Master Bobo strikes again! :bounce:

Exactly what I was looking for, but obviosly had no skills to do it.