[Closed] help with scripts for materials
Two parts to this…
1: Pretty simple one here. I’m trying to write a script that will go through all (or just the currently selected object’s) materials in my scene and rename the material, and also rename the diffuse (or any) map name.
I need to do this since I’m working on scenes that are being exported and used in a real-time app. And if 2 materials, or maps, have the same name, then they get all messed up and confused when exported. Don’t ask me how this happens, but when merging/swapping scenes many different times, max sometimes doesn’t rename duplicates.
I’ve tried… showProperties($.material)
and gotten the list of properties for the currently selected object, but I don’t see any for ‘material name’ or ‘diffuse/spec/etc map name’… am I just missing it? Or do I have to get it a different way? I’m pretty sure I can handle the loop that will do all the work, but I just can’t find the right properties… any ideas?
I usually get the scene second hand, and have no control over how the other person organizes (or doesn’t) the scene. Even if I can just rename them ‘Material 1’, ‘Material 2’, ‘Map 1’, ‘Map 2’, etc… thats fine with me
Now that I think of it, something exactly like the ‘Rename Objects’ tool, but for materials.
2: This one is a little more difficult, i think. The scenes that I’m working on are generally high poly (for renders), that I then convert to low poly (for real-time). As such, the materials are generally not ‘Standard’, and usually ‘Arch&Design’. The real-time app we use obviously doesn’t support these types of materials, so I have to go through each one, copy the attributes (usually only; diffuse color/map, spec level, and opacity) and switch them to ‘Standard’. This is an utterly painful process (some scenes have 200+ mats). I’m looking to take care of this with some scripts.
I can think of a few way to do this one, but I’m looking for some advice. Should I just record the attributes that are useful (diffuse color/map, spec level, and opacity) into variables, create a new material, and then transfer over these attributes? Or can someone think of a different/better way?
Thanks in advance,
Noisymonk.
“$.material.name” is where you find the material’s name.
“$.material.maps” is an array of all the maps in the material which you can step through and check if they’re not undefined and then use “$.material.maps[n].name”
One thing though, if your objects have multi-materials, you need to check for that first and then rename the sub materials.
No need to create any variables. Just step through your objects; create a new standard material for each one, and write the values you’re interested in from the arch/design materials directly into this new material and then apply that material to the object.
Well then. Not sure how I didn’t see those… or couldn’t figure that out, but thanks! That’s exactly what I was looking for. I don’t have the time to test out #2 just yet, but when I get the chance I’ll let you know how that goes.
Thanks again!
Erm… im having a situation similar to the second part.
What im trying to do is get the diffuse and alpha maps from the selected objects and apply them on some other material (GTA material)
heres the code
for geo in selection do
(
mat = geo.material
for i = 1 to $.count do
(
setmeditmaterial i (GTA_Mtl colormap: mat[1].diffusemap)
)
)
but for some reasons its just placing only one diffuse map on all the material slots.
could anyone help me out please.
heres the code
for geo in selection do ( mat = geo.material for i = 1 to $.count do ( setmeditmaterial i (GTA_Mtl colormap: mat[1].diffusemap) ) )
but for some reasons its just placing only one diffuse map on all the material slots. could anyone help me out please.
that because you are looping through the selection then looping through all the material slots and setting to the same bitmap. I don’t have the scene file so this could be buggy try it should give you some idea.
for i = 1 to selection.count do
(
mat = selection[i].material
setmeditmaterial i (GTA_Mtl colormap: mat[1].diffusemap)
)
edit: my bad forgot to remove the geo from the loop
hmm…, tried it. Geo was not declared so had to write it like this…
For i = 1 to selection.count do
(
for geo in selection do
(
mat = geo.material
setmeditmaterial i (GTA_Mtl colormap: mat[1].diffusemap)
)
)
and it gives the same old result.
it looks like you want to reapply materials for selected geometry with multimaterial using diffuse texture map of first submaterial…
if i’m right you have to:
for geo in selection as array where iskindof geo GeometryClass and iskindof geo.mat MultiMaterial and iskindof geo.mat[1] Standard do
(
geo.mat = GTA_Mtl colormap:geo.mat[1].diffusemap
)
Oh well thats exactly what i wanted, thankyou denisT.
You saved the day -lol.