Home Technical Talk

max batch material path?

polycounter lvl 18
Offline / Send Message
killingpeople polycounter lvl 18
So say I have a bunch of max scene files. Like most scene files, these files have materials that point to a specific filename located in a specific folder. Redirecting the path, I know how to do... so long as the material is named the same... My problem is, the texture file names are using (-) dashes in it's naming convention and we want to change them all to (_) an underscore, just like using a batch file renamer prog.

My question to you is, is there a feature, plugin, etc. that will enable someone to Find "This" in a Path/Filename and replace it with "That" for a handful of Max files?

Thanks good-look'n.

Replies

  • Mark Dygert
    File > Asset Tracking > Highlight the image paths > Right click and pick "set path"

    I'm not sure if you can script it or not...
  • killingpeople
    Offline / Send Message
    killingpeople polycounter lvl 18
    My bad, I kept editing my question so it would make more sense...
    The idea is to do this to like 10 max files, all in one mighty blow.
    Find "-" and Replace "_" for all max files in a directory or however you'd delegate that.
    Not just one at a time.
  • Eric Chadwick
  • Xenobond
    Offline / Send Message
    Xenobond polycounter lvl 18
    Might want to try this with copies of the files because it might make them invalid... -.-
    Could just use something like TextPad, and do a batch find/replace in the max files just by opening them in there.
  • MoP
    Offline / Send Message
    MoP polycounter lvl 18
    I wouldn't do that, Xenobond - if you just did a batch replace for all "-" with "_", then you'd probably break a ton of other stuff besides the materials you wanted to fix.

    I think it'd be pretty easy to write a maxscript that goes through all the materials in each scene, checks all their maps for bitmap paths, and replaces the "-" with "_".
  • Eric Chadwick
    Haven't cracked opened Max 2009 yet... are .max files not binary anymore?

    Can't edit a binary file in a text editor (unfortunately).

    Oh, also KP, I did a search for batch on scriptspot, there were a couple other scripts in the list that might be closer to what you want. Good luck man.

    Oh also there's a great bitmap-name find/replace script from Blur called Change Bitmaps that does a quick job, quicker & more automated than the Asset Tracker or the Bitmap Paths util.
    http://www.neilblevins.com/blurscripts/blurscripts.htm
  • MoP
    Offline / Send Message
    MoP polycounter lvl 18
    Edit: See my post below for a better script.
  • killingpeople
    Offline / Send Message
    killingpeople polycounter lvl 18
    Thanks guys, I feel the love and this helps out tons, I'll have to check more on these Monday!
  • Eric Chadwick
  • Xenobond
    Offline / Send Message
    Xenobond polycounter lvl 18
    MoP wrote: »
    I wouldn't do that, Xenobond - if you just did a batch replace for all "-" with "_", then you'd probably break a ton of other stuff besides the materials you wanted to fix.

    I think it'd be pretty easy to write a maxscript that goes through all the materials in each scene, checks all their maps for bitmap paths, and replaces the "-" with "_".


    Well that'd be a no-brainer. He did say that he was looking to rename a specific file being referenced. If he had is search and replace the filename as a whole, he wouldn't have to worry about any miscellaneous replacements throughout the files.

    Replace: file-name.dds
    Replace with: file_name.dds

    Can't get messed up there.
  • MoP
    Offline / Send Message
    MoP polycounter lvl 18
    Ehh, if you read his initial question, it sounded like they were changing naming conventions over from using "-" as a spacing character to "_" across a large amount of textures... and while it is possible to do a find and replace using a text editor (since it stores paths as plain text even though the rest of the file is binary), there are still other things which might get screwed up by doing that outside of Max, and you can only change individual characters, because if you changed the length of the string (for example by changing "-" to "--"), chances are the whole file would become unusable.

    Plus, I dunno how many text editors have batch file operations without having to open all the files at once...

    Either way, I'm writing a slightly better one now with a frontend dialog window, better error handling, and better replace options for Max 2008 - still working on the one for Max versions earlier than 2008 because they added a "replace string" command in 2008 which makes this sort of thing really easy.
  • MoP
    Offline / Send Message
    MoP polycounter lvl 18
    OK, I've written a better version.

    textureRenamer.jpg
    Click here to download it.


    Overview
    - Can replace any string (case-sensitive) in a path, filename or extension.
    - Works on every bitmap texture found in a scene (regardless of format).
    - Can convert paths to upper or lower case if necessary.
    - Tested on Max 8 and Max 2008.
    - Runs as a MacroScript - you will find it in the Customize menu under "MoP's Tools" category, I recommend you drag it to a toolbar.

    Some suggested uses
    - Change a whole set of scenes which point bitmap paths to a certain folder, to point at a different folder.
    - Change a whole set of scenes to point at .tga format instead of .psd
    -
    Make all your texture paths lower-case for compatibility.

    I ended up doing this because I figured I might find it useful too at some point. While I'm aware that there are probably scripts like this out already (several links in this thread seem to indicate as such), I wanted to learn a bit more scripting. :)

    Let me know if you come across any bugs. I tried to be fairly thorough, I didn't manage to break it yet... but you guys are all monsters, I'm sure it'll be torn apart in no time :)

    I also had to write custom functions for upper-case, lower-case conversion, and find/replace within a string ... Max 2008 has all of these built in as easy maxscript commands, but Max 9 and earlier don't, and I wanted at least a bit of backwards compatibility. If you're using Max 2008, it will use the Max 2008 algorithms, since I guess it might be a bit faster than my method.

    Disclaimer
    I strongly advise you back up any files or copy them to a new folder before running this script. I am not responsible for any problems caused or data lost due to running this script on your Max files.

    Cheers,
    -MoP
  • Eric Chadwick
    Oooh, this could come in handy.

    Disclaimer: my solicitors at Dewey, Cheetham, & Howe will be contacting you shortly.

    Thanks MoP!
  • killingpeople
    Offline / Send Message
    killingpeople polycounter lvl 18
    Many thanks MoP! Holy shi-, You rock!
  • killingpeople
    Offline / Send Message
    killingpeople polycounter lvl 18
    Hey Mop, I tested your Script out this morning and... I am a monster! Rar! :( It isn't working 100% for me but, I see the light!

    I copied 6 work max files into a new folder: C:\Rename

    The real names of these files have been changed to protect their real identity:

    1.A_B_Head01.max
    2.A_B_Head02.max
    3.A_C_Hair01.max
    4.A_C_Hair02.max
    5.A_C_Head02.max
    6.A_C_Head03.max

    *For every attempt below, my Replace entry was always: "_" with "-" using only the "Bitmap file name" process.

    Windows XP Professional SP2, Using Max 9, my first attempt, I ran the script from within A_B_Head01.max, it really disliked having the files set to Read-Only.
    Running the script, prompts an obvious texture path change made visible in the viewport. Closing Max will prompt a save. Clicking yes prompts the following IO Error:

    "The file <C:\Rename\A_B_Head01.max> is read-only. It will not be overwritten. Please use Save As to select new file name."

    That's no prob, and an acceptable exception I'd think.

    So restarting, my second attempt, I deleted and recopied the same 6 max files, disabled the Read-Only file attribute, and ran the script again within A_B_Head01.max and it kinda worked! It had only affected 1 of the 6 max files in the directory (The first, in alphabetical order). And, it only renamed the first, top right, Material Slot in the Material Editor.

    My third attempt is recopying the 6 files, disabling Read-Only, but running the script from an Untitled, fresh max scene, and entering all the same parameters. I can see it attempts to open A_B_Head01.max and run the script, but crashes with "Application Error".

    Same setup and result on my forth, only I attempted to run the script from "A_C_Head03.max", a file within the directory, but is not processed first. It seems it can't get past saving the first max file to continue on it's marry way.

    The script crashes Max on me while using the same "Replace entries" a second time, on the same directory and files. It seems to me it dislikes having nothing to change maybe? *does not compute! -- Ack! FIZZ!* ;)

    No pressure, but your Awesomeness is now on the line! Juuust josh'n ;)
  • killingpeople
    Offline / Send Message
    killingpeople polycounter lvl 18
    Oh dude, Joy.

    I deleted A_B_Head01.max and it ran through the remaining 5 max files correctly, changing all Materials, and all files, just as it's intended. It so works. The script doesn't like something in A_B_Head01.max... I'll keep testing it.
  • killingpeople
    Offline / Send Message
    killingpeople polycounter lvl 18
    I think it might be "Multi/Sub-Object" materials causing the error for me as that seems to be the only difference I've found so far.

    path_rename_00.gif

    path_rename_01.gif
  • MoP
    Offline / Send Message
    MoP polycounter lvl 18
    Woops, yeah, you're right, it only handles standard materials and lonesome texture map nodes at the moment.

    I'll see if I can quickly punch in Multi/Sub material support. Shouldn't take too long.

    Anything else wrong apart from that?

    EDIT: Fixed to work with multi-materials too ... download from the same location in my previous post. If the "Help" panel says "v1.1" then you've got the right version ;)
  • killingpeople
    Offline / Send Message
    killingpeople polycounter lvl 18
    I think we're totally golden with multi-sub materials support, and you've just made a dope little script and owe you a huge thanks!

    EDIT: Working like a fucking CHARM. YOU RULE!!!
Sign In or Register to comment.