Maxscript Rename textures/materials to filename, change file image extension

Maxscript Rename textures/materials to filename, change file image extension

system-core
Enthusiast Enthusiast
1,683 Views
5 Replies
Message 1 of 6

Maxscript Rename textures/materials to filename, change file image extension

system-core
Enthusiast
Enthusiast

image.png

I have scenes I need a single script to do the following

 

Change Texture name to filename on disk example: ClutterGenSmallA_d.dds

Change Material name to Texture file name

Change Image extension from .dds to .tga

 

I already found a script which changes the material to texture name, I cant seem to find a script which changes texture name to one on disk. If I can remove the path from the texture name

 

from: textures\SetDressing\ClutterGeneric\ClutterGenSmallA_d.dds

to: ClutterGenSmallA_d.dds

 

 

select $*
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

 

 

0 Likes
1,684 Views
5 Replies
Replies (5)
Message 2 of 6

system-core
Enthusiast
Enthusiast

I found some code that worked to change the texture map name to the same as the filename.

for b in getClassInstances bitmaptex do try(b.name = getFilenameFile b.filename)catch()
Message 3 of 6

dmitriy.shpilevoy
Collaborator
Collaborator

filenameFromPath @"D:\path\texture.tga"
"texture.tga"

0 Likes
Message 4 of 6

osukas
Advocate
Advocate

Im trying to do the same, but instead of a 3dsmax bitmap (bitmaptex) im trying to do it with an "Arnold Image" but i cant find the <MaxClass>

EDIT: i found it, is ai_image

for b in getClassInstances bitmaptex do try(b.name = getFilenameFile b.filename)catch()

for img in getClassInstances ai_image do try(img.name = getFilenameFile img.filename)catch()



0 Likes
Message 5 of 6

inquestudios
Enthusiast
Enthusiast
0 Likes
Message 6 of 6

MartinBeh
Advisor
Advisor

Have you considered doing this in the Asset Tracking System?

It has a function to strip the path from asset names...

Martin B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
0 Likes