ScriptSpot

Forum topic · Scripts Wanted

Rename Materials To Diffuse Texture Name

By TwilightZoney · 2014-01-24

Description

I'd like to rename all the materials in a selection of meshes whether that be multisub materials or not. Is this feasible to do?

Comments (19)

barigazy · 2014-01-24

Tell me which material do you want to rename (Standard, Arch&Design, VRayMtl)?

TwilightZoney · 2014-01-24

Just standard for them.

barigazy · 2014-01-24

This supports all tree ;)

fn renameMats objs = if objs.count != 0 do
(
local matClasses = #(Arch___Design__mi, Standard, VRayMtl)
local selMats = #()
for c in matClasses do
(
for o in objs where o.mat != null do (join selMats (getClassInstances c target:o))
)
if selMats.count != 0 do
(
for m in selMats do
(
case of
(
(isProperty m #diff_color_map): if isKindOf (map = getProperty m #diff_color_map) textureMap do m.name = map.name
(isProperty m #diffuseMap): if isKindOf (map = getProperty m #diffuseMap) textureMap do m.name = map.name
(isProperty m #texmap_diffuse): if isKindOf (map = getProperty m #texmap_diffuse) textureMap do m.name = map.name
)
)
) ; free selMats
)
renameMats selection

TwilightZoney · 2014-01-24

-- Frame:
-- selMats: #(wap_mapA_gate_nos_.xno0:Standard, wap_mapA_gate_nos_.xno1:Standard, wap_mapA_gate_nos_.xno2:Standard, wap_mapA_gate_nos_.xno3:Standard, wap_mapA_gate_nos_.xno4:Standard, wap_mapA_gate_nos_.xno5:Standard, wap_mapA_gate_nos_.xno6:Standard, wap_mapA_gate_nos_.xno7:Standard, wap_mapA_gate_nos_.xno8:Standard, wap_mapA_gate_nos_.xno9:Standard, wap_mapA_gate_nos_.xno10:Standard, wap_mapA_gate_nos_.xno11:Standard, wap_mapA_gate_nos_.xno12:Standard, wap_mapA_gate_nos_.xno13:Standard, wap_mapA_gate_nos_.xno14:Standard, wap_mapA_gate_nos_.xno15:Standard, wap_mapA_gate_nos_.xno16:Standard, wap_mapA_gate_nos_.xno17:Standard, wap_mapA_gate_nos_.xno18:Standard, wap_mapA_gate_nos_.xno19:Standard, ...)
-- objs: $selection
-- matClasses: #(Arch___Design__mi, Standardmaterial, undefined)
-- VRayMtl: undefined
-- Type error: getClassInstances requires MAXClass, got: undefined

Not sure what happened. I just selected all the meshes and tried executing it. Unless thats not the correct way to go about using this.

barigazy · 2014-01-24

Yup. You not have installed VRAY.

barigazy · 2014-01-24

Try this then

fn renameMats objs = if objs.count != 0 do
(
local matClasses = #(Arch___Design__mi, Standard)
local selMats = #()
for c in matClasses do
(
for o in objs where o.mat != null do (join selMats (getClassInstances c target:o))
)
if selMats.count != 0 do
(
for m in selMats do
(
case of
(
(isProperty m #diff_color_map): if isKindOf (map = getProperty m #diff_color_map) textureMap do m.name = map.name
(isProperty m #diffuseMap): if isKindOf (map = getProperty m #diffuseMap) textureMap do m.name = map.name
)
)
) ; free selMats
)
renameMats selection

TwilightZoney · 2014-01-24

Thats awesome, works perfectly now. Only thing I would like it to get rid of would be the added extension that is added to it.

.dds-image It adds this depending on if its a png or jpg. Is there a way to just make it search for it and just delete it.

barigazy · 2014-01-24

u want to remove extension from material name?
Like this?
"somename1.dds" -->"somename1"
"somename2.jpg" -->"somename2"

barigazy · 2014-01-24

This fn will remove extension from material name

fn renameMats objs = if objs.count != 0 do
(
local matClasses = #(Arch___Design__mi, Standard)
local selMats = #()
fn cleanName str =
(
if (strarr = filterstring str ".").count < 3 then return strarr[1] else (for i = 2 to strarr.count-1 do strarr[1] += ("."+strarr[i]) ; strarr[1])
)
for c in matClasses do
(
for o in objs where o.mat != null do (join selMats (getClassInstances c target:o))
)
if selMats.count != 0 do
(
for m in selMats do
(
case of
(
(isProperty m #diff_color_map): if isKindOf (map = getProperty m #diff_color_map) textureMap do m.name = cleanName map.name
(isProperty m #diffuseMap): if isKindOf (map = getProperty m #diffuseMap) textureMap do m.name = cleanName map.name
)
)
) ; free selMats
)

TwilightZoney · 2014-01-24

It executed fine, but it just didn't change anything.

Would still leave the material name like this.

wap_meca03_dfsp_o.dds-image

And if I try it how the material name normally is it won't change anything at all.

Not sure if its just because its a MultiSub Materials or not.

barigazy · 2014-01-24

this will only rename Standard and A&D material name but not multimaterial

barigazy · 2014-01-24

probably you forget to run this line after you run previous fn

renameMats selection

Physical material and materials in multimaterial

d1myan · 2025-10-09

Hi! tell me: is it possible to fix this script so that it works with Physical material too and with materials in multimaterial?

Hi

SimonBourgeois · 2025-10-26

you can use this:


(
	fn renameMats objs texturename:off = if objs.count != 0 do
(
	local matClasses = #(Standard,PhysicalMaterial)
	local selMats = #()
	fn cleanName str =
	(
		if (strarr = filterstring str ".").count < 3 then return strarr[1] else (for i = 2 to strarr.count-1 do strarr[1] += ("."+strarr[i]) ; strarr[1])
	)
	for c in matClasses do
	(
		for o in objs where o.mat != undefined do (join selMats (getClassInstances c target:o))
	)
	if selMats.count != 0 do
	(
		for m in selMats do
		(
			if texturename do bitmaps = for map in (getClassInstances bitmaptexture target:m) where map.filename != undefined collect map
	
			case of
			(
				(isProperty m #diffuseMap): if isKindOf (map = getProperty m #diffuseMap) textureMap do (if texturename and bitmaps.count > 0 then m.name = getFilenameFile bitmaps[1].filename else m.name = cleanName map.name)
				(isproperty m #base_color_map): if isKindOf (map = getProperty m #base_color_map) textureMap do (if texturename and bitmaps.count > 0 then m.name = getFilenameFile bitmaps[1].filename else m.name = cleanName map.name)
			)
		)
	) ; free selMats
)
renameMats selection texturename:on
)

I added an optional argument to use texture names instead of map names,just use texturename:off if you need the map name rather than the texture filename.
It will check for any bitmap texture in the material that has a file path and use the first found bitmap file name as a material name

d1myan · 2025-10-09

Hi! tell me: how do I add Physical material here?

script to remame textures

jnls · 2019-03-25

I have searched scriptspot and I have not found any script that changes the name of the textures in max and that at the same time rename these in the hard disk in a massive way because often the 3d models contain textures and maps with names numbers and even Chinese letters , Russians that are a total mess, I hope you could create a script that can do this, rename textures in max and in the hdd and update automatically in the routes.
I hope it's understandable because I'm using the Google translator

StormBrig · 2019-03-25

This is a very good idea.

jnls · 2019-03-27

Greetings miauu

I have dealt with Interactive Universal Renamer and the best free option
I can find is duber bitmap collector but it has not been updated, hopefully with your knowledge you could modify it and improve it in these points: when renaming the textures and maps are not duplicated, when opening it load automatically the textures without having to look for the route in the browser, be able to sort them alphabetically and the option of saving the new name in the same input folder automatically.