Home Technical Talk

Max Script Question

I'm currently going through the Andrew Gahan "3DS Max Modeling for Game" so far a very good book, nearer the end he mentions using MAX Script to speed up workflow, so just out of curiosity, has writing a script saved you much time for doing repetive tasks? He mentions it is easy to learn, and coding isn't my weak point, but is it time consuming, as a final year Uni Student, time isn't something I have a lot of (Polycount posting interesting news doesn't help!)... but if I can save time using Max Script. I'm all (both) ears.

Thank you for any advice you can give :)

Replies

  • Noors
    Options
    Offline / Send Message
    Noors greentooth
    Takes less time to code a loop than duplicate and place thousands of objects by hand for example. So, yeah scripts are time saver, i use them constantly, for naming stuff, set materials...
    But most of what you need or close has already been scripted. Sometimes just little modifications are needed + you have a maxscript listener in max, where are listed all the action you do, so, it's pretty easy to start with it.
    Scriptspot.com is the best source.
  • Mark Dygert
    Options
    Offline / Send Message
    Yes... oh gawd yes has it helped me.

    One thing to keep in mind is, will writing this script take more time then all the time it will save? In other words if its just to get you out of doing a task once and you'll never use it again, probably suck it up and do it manually unless its super easy to crank out. Before you sit down and try to script anything make sure that someone hasn't already gone to the trouble and done what you're about to do, check www.scriptspot.com.

    Example #1: Lets say you like turbosmooth to be applied with Isoline On and Itterations set to 3, but the default is off and 1. With the maxscript listner window on I know that when I apply turbosmooth and make those changes it looks like this:
        modPanel.addModToSelection (TurboSmooth ()) ui:on
        $.modifiers[#TurboSmooth].isolineDisplay = on
        $.modifiers[#TurboSmooth].iterations = 3
    
    If you combine that with a header and wrap it in () and you have a working script. When you run the script it will add it to Main Menu > Customize > Customize UI from there you can have a button, a keybind or add it to the quad menu.
    macroScript TurboCustom
    Category:" VigTools"
    toolTip:"TurboCustom"
    buttonText:"Customized TurboSmooth"
    
    (
        modPanel.addModToSelection (TurboSmooth ()) ui:on
        $.modifiers[#TurboSmooth].isolineDisplay = on
        $.modifiers[#TurboSmooth].iterations = 3
    )
    
    Now turbo smooth is set up the way you like it, every time. Now how many other menus are you changing the defaults on and something like this that takes 30sec will help you avoid a few mouse clicks?

    Example #2: I have a bunch of max files that are bloated, running the File > New > Keep objects and Hirearcy option cuts their file size down quite a bit. There are a lot of clicks and it loads the objects into a new scene called untitled I want it to save with the same name and I want less mouse clicks. So again with the macro recorder I see that:
    actionMan.executeAction 0 "18"  [I][COLOR=DarkOliveGreen]-- File: New Scene, Keep Objects and Hierarchy[/COLOR][/I]
    
    Is called when I do that command. But that only gets me to the new untitled scene so I need to add to it. With a little help from the MaxScript help file I manage to do this in a few min:
    [I][COLOR=DarkOliveGreen]--header[/COLOR][/I]
    macroScript CleanSaveAndOpen [I][COLOR=DarkOliveGreen]--this will cause the script to be saved internally inside of 3dsmax[/COLOR][/I]
    Category:" VigTools" [I][COLOR=DarkOliveGreen]--this is the category inside the Customize UI menu[/COLOR][/I]
    toolTip:"Clean Save and Open" [COLOR=DarkOliveGreen][I]--the name of the script in the Customize UI menu, also the tooltip when you mouse over a button[/I][/COLOR]
    buttonText:"CleanSave"[COLOR=DarkOliveGreen][I]--yea you guessed it[/I][/COLOR]
    [COLOR=DarkOliveGreen][I]--/header[/I][/COLOR]
    
    (
        local fpath = maxfilepath [COLOR=DarkOliveGreen][I]--stores the path of the currently opened file[/I][/COLOR]
        local fname = maxfilename [COLOR=DarkOliveGreen][I]--stores the file name[/I][/COLOR]
        local oldpath = maxfilepath + maxfilename [COLOR=DarkOliveGreen][I]--stores both[/I][/COLOR]
            actionMan.executeAction 0 "18" [I][COLOR=DarkOliveGreen]-- File: New Scene, Keep Objects and Hierarchy[/COLOR][/I]
            getSaveFileName filename:fname historyCategory:fpath [COLOR=DarkOliveGreen][I]--this brings up the save as dialog and fills in the necessary info, I do this instead of force a save in case I don't want to overwrite or I want to save in iteration 001 [/I][/COLOR]
            loadMaxFile oldpath [COLOR=DarkOliveGreen][I]--this opens the file I just saved[/I][/COLOR]
    )
    
    So when I encounter one of those bloated files in one button it its cleaned and reloaded. I've also set this up so it can batch a bunch of max files in a folder but I won't get into that script as it was more complicated and pretty much does the same thing.

    Hopefully that wasn't too crazy and is easy to follow.
  • SteveyConlan
    Options
    Offline / Send Message
    Strangely enough all that made perfect sense, the commands look really simple, well at the minute I'm editing via edges, clicking ring and connect so I might start out with something simple like that. Figuring by the reactions it has saved quite a bit of time so I'll be sure to check out the website.

    I don't mind clicking away and using the odd key shortcuts I know but some tasks do get tedious and repetitive so I guess in the long run it will pay off. Looking at the script you just planned out Mark it looks like I could pick it up in under an hour, call a command declare its settings move on.

    (I actually thought it would be a lot more complicated, I'm not sure how I imagined it, but certainly not as straightforward as you made it look)

    Thanks a lot I think I'll give it a little go now :)
  • Mark Dygert
    Options
    Offline / Send Message
    Well good, I've hit a few people with examples like that and their brains explode so you're probably in good shape to pick it up. Its the most artist friendly language I've seen.

    For the most part if people can record actions in PhotoShop they can "write" simple scripts that save time. A bunch of those people can take it deeper, and a few more of those people can make a job out of it improving artists lives and being heros to us all like BoBo (not our Bobo Brian Jones) but the scripting Juggernaut BoBo who pretty much wrote the maxscript help files. Or Paul Neale, Ben Cloward, Rob Galanakis, and my personal hero Neil Belvins. These are all people who have been part of the community at large that have been responsable for some amazing improvements through scripting. They started out pretty much the exact same way you are now. No pressure =P

    It does get a more complicated but the maxscript help file, Help > Maxscript Help (or F1 with the maxscript editor open) most things can be learned.

    The biggest draw back to maxscript is their support of legacy tools modes and meshes, so many ways to do the same thing. There are times when you'll have to write 20 lines of code just to variety what you're about to do can be done on the object in questions because it could be one of 4-5 other types of meshes that are almost identical but have different commands.
    Editiable Mesh, the object.
    Edit Mesh, the modifier.
    Editiable Poly, the object.
    Edit Poly, the modifier.
    If you're nudging verts around each of these has a slightly different way to do the same thing. They're working on improving this from what I hear but its tedious. Almost all script writers finish a script and then get a bug report that deals with a mode they didn't think to deal with. In other apps its easier because they have one mesh type and one set of commands but thats life I guess.
  • shawnolson
    Options
    Offline / Send Message
    shawnolson polycounter lvl 13
    Well good, I've hit a few people with examples like that and their brains explode so you're probably in good shape to pick it up. Its the most artist friendly language I've seen.

    I agree that it isn't super hard... but as easy as it is... MAXScript keeps throwing curve balls into my brain! It has so many conventions that are different than the languages my other life deals with (ActionScript, Java, JavaScript, PHP, etc). I find myself being influenced by the style of the documentation or tutorial of the minute... only to find that I'm moving from if..do to if...then...else (a crazy controvery about that one on some forum, maybe at the Area) to not using parenthesis around function parameters to no semicolons ending lines... etc.

    In the end, it may be more confusing for me because I've used other languages than had it been my first language...

    In any event, it's growing on my and I do like it... I just wish it were more conventional.
  • xXm0RpH3usXx
    Options
    Offline / Send Message
    xXm0RpH3usXx polycounter lvl 13
    also, sometimes you can already achieve great stuff with the listener, if you write code down there and hit enter it executes that line.
    that awesome if you for instance want to add a materialid modifier on a bunch of meshes and set the ids randomly, its only one line with a loop and saves ALOT of time....
  • Mark Dygert
    Options
    Offline / Send Message
    It's pretty open to just about anything you throw at it, its nuts at times and because it's evolved so much and so many outside people have had hands in creating bits and pieces that have plugged into over the years its a pain to learn the way each piece works.

    It really helped me get to get a feel for it all when i grabbed some scripts and tore them apart.
  • renderhjs
    Options
    Offline / Send Message
    renderhjs sublime tool
    I wouldn't want to work with max without my own scripts that I created over the years. It helped me migrate every time to a new installation of 3dsmax and speeds up my workflow immensely.
    Most scripts I write are about killing nagging steps that I hate enough to fix them, I like one button solutions were the script does smart stuff context based. I hate on the other hand bloated UI's and steps where I need to pay extra attention to not do something wrong. Like some of the exporter dialogs of max (fbx comes to mind).

    At my work I use 3dsMax mainly as a level generation tool. So I create content and a game level or layout in 3dsmax and then usually write a maxscript to export it to the game engine.
    Because of that max is just as important as Photoshop to me, because its a extremely powerful toolbox that gets even more powerful with MXS (maxscript).


    Mark already wrote very good tips, just if you want to start something always look first at scriptspot if there is already a similar script there. Look at the script and try to understand it or modify it to your needs. Thats how I learned a lot of things.
    The biggest thing I wrote so far was TexTools
    textools3.jpg
    There is quite a lot you can do with just maxscript :)

    Recently I wrote some tools for Unity
    UnityMeshExporter_script.gif
    and its basically to save frustration and tedious tasks, so I can focus on the things that are more fun.

    Shoot some maxscript questions here at the Tech Talk section, I'll make sure I will try to answer some of them :)
  • RobH2
    Options
    Offline / Send Message
    RobH2 polycounter lvl 4
    I know this is an old thread but it's a really helpful thread. Mark, thanks for the header modification info. I've been having go repeatedly to the menu and having to navigate and use several click to use a script I like over and over. It's so nice to have a button for it. Thanks...
Sign In or Register to comment.