PDA

View Full Version : newbie question replace mat


Peterwildman
10-03-2005, 04:20 PM
I'm just starting to learn maxscript so I'm writing a script to replace materials. I know there are a ton of script out there that already do this I just want to see if I can do it. I've got everthing working fine except I cant figure out how to replace the old material with the new one i've created. Which is pretty much the whole idea. I'm look for a forced update comand or something like that. example if you are just using max and you have a material named "red" and you make another material named "red" max will ask you do you want to replace this material? and you hit yes and your new "red" material takes place of the old one and it is assigned to all the objects that the old one was orginal assigned to.
My script curently just makes two materials named red instead of replace old "red" with new "red" how can I fix this?
Thanks, I hope this all makes sense

Blue
10-03-2005, 05:42 PM
Instead of making a new material, why not just edit the existing one?

Max object names are not unique identifiers, any number of objects can share the same name.

RyanT
10-03-2005, 06:43 PM
Peter-

Try this,

type obj = sphere()
this creats a sphere and the variable obj holds that sphere in it

type obj.material in your maxscript listener. If it returns undefined then the object has no material assigned to it yet.

type foo = standard()
the listener returns Standardmaterial:Standard so now foo is a new material

to get the properties of the standard material type

type foo.name = "Red"
Now the foo material is named red.

type foo.diffuse = color 254 24 24
now the color is red

type showproperties foo
there are alot of properties that it returns, any one of them you just type foo.property and you can change that property in some way. If its a string it needs something like this "Red" if its a boolean it needs either true or false. You can look up any of these in the maxscript reference. This is a must. If your not looking stuff up in the reference start now. Some times you can use the search to find things and sometimes using the index tab is better for specific properties you are looking up.

type obj.material = foo
you now have applied the foo material to your object


-RyanT

Peterwildman
10-03-2005, 07:54 PM
Thanks guys for the fast reply. I think I haven't been clear on my question
here is my script so far.


utility assign_material "Assign Material"
(
button sel_bmp "switch Bitmap" width:120

on sel_bmp pressed do

for i in 1 to scenematerials.count do

( meditMaterials[3] = scenematerials[i]

if classof meditMaterials[3] == Standardmaterial then
(
b = sphere()
b.name = "matersphere"
meditMaterials[1] = VRayMtl ()
meditMaterials[1].texmap_diffuse = copy meditMaterials[3].diffuseMap
meditMaterials[1].name = copy meditMaterials[3].name
b.material = meditMaterials[1]

)
else messagebox "not standard"
)

)
what i want is a line of code that does excally what this max dialog does.
http://www.wildman3d.com/dialog.jpg

so that my script replaces the materials in the scenematerial
rather than just adds them

galagast
10-04-2005, 03:21 AM
im not sure, but i suppose what you need to do is loop through all your scene objects, check who has the material and replace it with the new one...

probably something along these lines...
for i in $* where i.material == old_material do i.material = new_material

hope this helps
:)

Blue
10-04-2005, 05:25 AM
Thanks guys for the fast reply. I think I haven't been clear on my question
here is my script so far.

what i want is a line of code that does excally what this max dialog does.
http://www.wildman3d.com/dialog.jpg

so that my script replaces the materials in the scenematerial
rather than just adds themThis is what I had thought you wanted, but there is not a way to trigger this prompt that I know of, thus the explaination of the non-unique names. This is why I had suggested just editing the original as it would have the same end result. What you had asked for was to replace an existing material with a new one, editing the old material to reflect what the new material was to be would be the same result.

If you have to have this prompt, querry if the texture exists in the scene yourself and then display a custom made scripted dialog on a returned true result. This way your script could still let the user OK or Cancel the material change.

Peterwildman
10-04-2005, 12:38 PM
Thank you
The thing about changing the original is that when I set the Material type
meditMaterials[1] = VRayMtl () it automatically makes a new material. How can
I change the type without making a new material???
thanks again for all your help

CGTalk Moderation
10-04-2005, 12:38 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.