Home Technical Talk

Need max script! PSD extension swapper

polycounter lvl 18
Offline / Send Message
Delaney King polycounter lvl 18

Any of you script monkeys want to show off?

I love painting in .psds but like to bring them down to bmps, jpgs and tgas.. nowadays its getting really time consuming to do all the repathing!

I would like to see a script that looks at all the maps in a max scene (or selected objects if you want to be really nice), finds any with the .psd extension, checks if there are any other maps with the same name but with any other extension in the folder and switches them automatically.

So a material with "bobshead.psd" finds "bobshead.jpg" in the same folder and decides to swap it.

Cheers!

Replies

  • FatAssasin
    Options
    Offline / Send Message
    FatAssasin polycounter lvl 18
    Why not just load up the .jpg to begin with and do a "Save As" from Photoshop each time you make changes?
  • sinistergfx
    Options
    Offline / Send Message
    sinistergfx polycounter lvl 18
    This seems like this might be a fairly easy max script. I -might- look into it.

    EDIT: working on it now, :P.
    I'll be able to reuse some material handling from another script I wrote, so it shouldn't take -too- long.
  • ScreaminBubba
    Options
    Offline / Send Message
    ScreaminBubba polycounter lvl 18
    A maxscripter I work with will be making me something like this soon, as I have hundreds of assets that point to psd files that need to change over.

    I'll post it when he makes it, probably in the next week or so.
  • sinistergfx
    Options
    Offline / Send Message
    sinistergfx polycounter lvl 18
    I should have it done in a day or so :P.
  • Rick Stirling
    Options
    Offline / Send Message
    Rick Stirling polycounter lvl 18
    I had a wee think on the way home from work tonight.

    It's not a hard script to write in theory. Is it all the materials in the scene, or all the materials in the material editor?

    I take it you are also using multi-sub objects?

    Unless I can see another way, it will only work with build in max shaders - my method wouldn't work with some 3rd party ones as they don't always provide an API.

    Basically:

    There are 24 material slots, so for each slot:
    Check to see if the matial is of type bitmap
    Check each sub material.
    Check each map slot (difuse, spec, bump etc)
    get the image extension (easy)
    if its psd, get the full path, get the file name withour extension
    build a new string of path+file+ ".jpg"
    set current mateiral to use the new path.

    If none of the other guys get you one, I'll knock you one up. The edinburgh festival is wrapping up, and I still have a few comedy shows to go to and 2 gigs (The Licks and The Pixies, yay!) so it'd be next week before I got a chance.

    Some quick bits


    for the ENTIRE SCENE use

    for i in $* do
    (
    do stuff
    )
    )


    check to see if the material is actaully a bitmap before trying to swap it

    if classOf theMaterial == BitmapTexture then



    For each material, check to see if it is a multisub. If not, call the switching extension funtion ont he material. If it is, get the number of subs, and then for each sub call it.





    I'd have a go at home, but Max doesn't run on my mac.
  • ScoobyDoofus
    Options
    Offline / Send Message
    ScoobyDoofus polycounter lvl 19
    This is all great ,but you could just use layered .tifs!

    It's basically a .psd with a .tif extension and 3D Studio reads it just as if it were a flat targa.

    That is what I do.

    *Ack after re-reading this thread, I understand the problem.
    Very few engines use .tif, and even if you backed up your layered version, and flattened the ones used in the scene...they would still be .tifs, which would require you to convert & repath pre-export if the engine didn't support .tif's.

    Right?...or am I just not getting it?
  • sinistergfx
    Options
    Offline / Send Message
    sinistergfx polycounter lvl 18
    I have a system already written that either looks through all the materials in the scene or just those of the objects you have selected. It can also parse through multi-sub materials with just about infinite levels of nesting. Works with many types of materials, not just standard.

    I just have to learn how to do file searching and string modification to do what Dave wants.

    Forgot to transfer a work in progress version to my home computer to work on it tonight, so it'll have to wait till work/after work tomorrow.
  • Rick Stirling
    Options
    Offline / Send Message
    Rick Stirling polycounter lvl 18
    filenameFromPath <filename_string>
    Returns the file name and extension of a full file name, useful for labeling file buttons in rollout panels.

    getFilenamePath <filename_string>
    Returns the directory path part of a full file name.

    getFilenameFile <filename_string>
    Returns the file name part of a full file name.

    getFilenameType <filename_string>
    Returns the type extension part of a full file name.

    doesFileExist <filename_string>
    Returns true if the file exists, false otherwise

    Examples:
    file="g:\\subdir1\\subdir2\\myImage.jpg"

    filenameFromPath file -- returns: "myImage.jpg"
    getFilenamePath file -- returns: "g:\subdir1\subdir2\"
    getFilenameFile file -- returns: "myImage"
    getFilenameType file -- returns: ".jpg"
  • Eric Chadwick
    Options
    Offline / Send Message
    Hmmm. Why re-invent the wheel? If I understand you correctly, you just want to replace all the .PSD extensions with a different one.

    Blur Studios' ChangeBitmaps does a great job:
    http://www.neilblevins.com/blurscripts/blurscripts.htm
    Also does paths. You can limit it to certain criteria too... All Scene Materials, Materials On Selected Objects, etc.

    Or you could use their Renamer, which does even more.

    But I guess you want something a bit smarter, that checks to see if the new extension exists?
  • sinistergfx
    Options
    Offline / Send Message
    sinistergfx polycounter lvl 18
    That looks good. So what the hell am I doing?
  • Eric Chadwick
    Options
    Offline / Send Message
    Hahah, I dunno! Always good to know what's out there already. Although coding for learning's sake is a good thing too.

    FWIW, I made screengrabs of those two tools, so you can see what they do.

    blur_changebitmaps.gif

    blur_renamer.gif
  • Delaney King
    Options
    Offline / Send Message
    Delaney King polycounter lvl 18
    nice. Oh, the reason I use PSD is because I use Ghostpainter... and it lets me paint directly on only one layer at a time... very nice (but awkward) program.

    I wouldnt use layered tiffs because the end result needs to be small and FTP'able.

    Thanks all for your help and I hope you enjoyed the mental work out!

    Dave
    ________________________

    Max 8 has a make pretty button.
Sign In or Register to comment.