Changing Texture Format

Has there been a script that is on there that will allow me to switch currently assigned textures to a different format? We received a rather large project with hundreds of textures in .tiff format. The problem is, these textures all totaled are over 3 gigs of memory. I've converted the textures to a more manageable file type, but can I bulk switch them? Say switching them all from .tiff to .jpeg or whatever format we end up going with. The names will stay exactly the same, it's just the file extension.

Comments

Comment viewing options

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

great

thx

real08121985's picture

woooooooooooooooooooooooooooo

wooooooooooooooooooooooooooooooooooord ;)

Andrue's picture

Thanks! YOU ARE THE MAN! I

Thanks! YOU ARE THE MAN! I search this script hole day, and now I find it, and it works perfectly! Thank you! Thank you! Thank you!

paulov's picture

This morning I was wondering

This morning I was wondering if this could be possible as I found a nice 3d texture maker but it only exports in jpg , tiff tga... and I use dds, but this way I can go mapping all the objets and when I've all the textures converted tu dds do the swap.

THanks for the script!

real08121985's picture

I got the same problem some

I got the same problem some time ago. Note this script ignores case.

(
	local sFrom = "tga" -- previous format
	local sTo = "jpg" -- the format that we want
 
	local aBmaps = getClassInstances BitmapTexture
	for Bmap in aBmaps do (
 
			local sFilename = Bmap.filename
			local sPath = getFilenamePath sFilename
			local sFile = getFilenameFile sFilename
			local sType = replace (getFilenameType sFilename) 1 1 ""
 
			if toLower sType == toLower sFrom do Bmap.filename = sPath + sFile + "." + sTo
	)
)
3dwannab's picture

Got it working

This code only trims the filename from the left. I wanted to replace 'Archmodels' with 'AM'. Here's the code. Thanks for a starting point.

ReplacedString = "archmodels" as string
NewString = "AM" as string
patternIs = NewString + NewString + "*"
theMaps = getClassInstances BitmapTexture
 
for i in 1 to theMaps.count do (
	fileName = theMaps[i].filename
	newFilename = trimleft fileName ReplacedString
	new2filename = NewString + newFilename
 
	if matchPattern new2filename pattern:patternIs ignoreCase:false == false then (
	theMaps[i].filename = new2Filename
	)
)
barigazy's picture

...

This solution will replace all "archmodels" strings with "AM" only if "AM..." file realy exists.
I did'nt test this but I hope that works ;)

fn replaceFilename currentString: withString: =
(
	fn isValidMap map = isKindOf m.filename string and matchPattern m.filename pattern:(currentString + "*")
	local maps = getClassInstances BitmapTex
	local appendPath = pathConfig.appendPath
	if maps.count > 0 do
	(
		for m in maps where isValidMap m do
		(
			path = getFilenamePath m.filename
			name = filenameFromPath m.filename
			if doesFileExist (string = appendPath path (substituteString name currentString withString)) do
			(
				setProperty m #filename string
			)
		)
	)
)
replaceFilename currentString:"archmodels" withString:"AM"

barigazy

3dwannab's picture

Hi barigazy. Thanks for the

Hi barigazy. Thanks for the code. But it's throwing an error on line fn isValidMap like -- Error occurred in anonymous codeblock;. I've since get this working with the help of pixamoon over on a seperate thread I created. http://www.scriptspot.com/forums/3ds-max/general-scripting/convert-undef... Here's the code.

OldString = "Arch137" as string -- Change to suit
NewString = "AM137" as string -- Ditto
theMaps = getClassInstances BitmapTexture
for i in 1 to theMaps.count do (
	fileName = theMaps[i].filename
	if matchPattern fileName pattern:"AM*" ignoreCase:false == false then (
		newFilename = trimleft fileName OldString
		new2filename = NewString + newFilename
		theMaps[i].filename = new2Filename -- renames
	)
)

One downside of this is it only replaces the first instance of the string but it works well :)

3dwannab's picture

Great!

Is it possible for this to work with changing the filename and not the extension also. Tried to edit what you had but without luck. Thanks.

ManoloStai's picture

Changing texture format

Holy Cow!!!!!!!
This is awesome, amazing....
this really really helped
Thank you so much

Comment viewing options

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