Rename Materials To Diffuse Texture Name

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

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
barigazy's picture

...

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

barigazy

TwilightZoney's picture

Just standard for them.

Just standard for them.

barigazy's picture

...

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

barigazy

TwilightZoney's picture

-- Frame: -- selMats:

-- 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's picture

...

Yup. You not have installed VRAY.

barigazy

barigazy's picture

...

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

barigazy

TwilightZoney's picture

Thats awesome, works

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's picture

...

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

barigazy

barigazy's picture

...

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
)

barigazy

TwilightZoney's picture

It executed fine, but it just

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.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.