Notifications
Clear all

[Closed] replace bitmap file type

Hey, I have a scene and I converted my textures to be jpgs from tifs to save space (doing some testing so quality isn’t a big deal.” But now in my Max scene I’d like to change all my bitmap links to be .jpg instead of .tif. So the bitmap path would change to something like “C:\bitmap1.tif” —> “C:\bitmap1.jpg” Far as I know the Asset Tracking and Bitmap Paths dialogs don’t do what I want to do. Is there a way to do it in maxscript? I don’t know much about maxscript. Thanks!

7 Replies

Did something like this awhile ago, different reasons though.

  1. Get the texture path as a string.
  2. Change the last three string characters from tga to jpg.
  3. Set the texture path to be the edited string.

Thanks, you wouldn’t by chance know the maxscript for this would you? As I said, I don’t know any maxscript really…

where are your bitmaps used? are they always in a bitmaptexture?

If you want to be dangerous you can do it without opening the file and directly to the file.
MAX File Asset Metadata Stream Access. I highly recommend do a file copy to newly named/versioned file and then tweaking with the metastream.

Basically it should work something like this:

srcFile = someFile.max
newFile = someFile-new.max
copyFile srcFile newFile
typeIn = "tif"
typeOut = "jpg"
srcData = getMaxFileAssetMetadata newFile
for assets in srcData do (
    if (matchpattern assets.filename pattern:("*"+typeIn+"*")) do (
        (replace assets.filename (assets.filename.count-2) 3 typeout)
    )
)
setMaxFileAssetMetadata newFile

-Eric

2 Replies
(@polytools3d)
Joined: 11 months ago

Posts: 0

That Statement is dangerous:

(
       	typeIn = "tif"
       	typeOut = "jpg"
       	filename = "C:\skin_02_beautiful_01.tga"
       	
       	if (matchpattern filename pattern:("*"+typeIn+"*")) do
       	(
       		(replace filename (filename.count-2) 3 typeout)
       	)
       	
       	-- "C:\skin_02_beautiful_01.jpg"
       )

Perhaps you could use getFilenameType() instead or pattern:(“*”+typeIn)

(@pixel_monkey)
Joined: 11 months ago

Posts: 0

Yeah

typeIn = ".tif"
if (getFilenameType assets.filename) == typeIn do

is probably the safer method, however you will need the filetype in the “.tif”, “.jpg”, string with the leading dot.

-Eric

I’ve used .net to deal with file extensions for a while now. This will either add the extension if it isn’t there yet, or replace an existing extension.

(dotnetclass "system.io.path").ChangeExtension theFilePath ".jpg"