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.
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.

barigazy's picture

...

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

barigazy

barigazy's picture

...

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

renameMats selection

barigazy

Comment viewing options

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