Chapter 6. Scripting by Jon SeagullWe 3D artists hate repetitive tasks. After all, we were led to believe when we signed on for this gig that the computer was going to be doing all the grunt work. While this idea is at its core true, a few late nights troubleshooting scenes under a looming deadline have beaten the naive luster off of it for most of us. (If they haven't, bookmark this chapter. You'll be wanting to reread it in a couple of months.)We love our tools, but there are times when it seems that they don't quite work exactly the way we want at the moment, or that if some incredibly esoteric feature existed, we'd be able to get to bed a few hours earlier. Wouldn't it be great if in those moments you could magically conjure up the exact tool you needed?Well, you can. Seriously. That's what MAXScript (sometimes referred to as MXS) is for. If you're lucky enough to:(a) do this for a living(b) work at a studio with the resources to hire a technical director,then you most likely already know the power of MAXScript. The thought of writing code yourself may still make you nervous, however.Many artists seem to tense up when the subject of MAXScript arises. They feel that it's unpleasantly technical, worry that they won't be able to learn it for lack of programming experience, or just don't see a practical use short of total expertise, which they don't really want.Much of the intimidation stems from the fact that there are really two faces of MAXScript: the polished tools written by technical directors or downloaded from the Internet, containing dozens, hundreds, or thousands of lines of code; and the interactive Listener, into which you can type commands to manipulate your scenes. Most people think of MAXScript exclusively in terms of the former aspectit's what you have contact with as a nonscripter, and if you peek at the code for a substantial script, it can be intimidating. The other face of MAXScript, though, the quick and interactive one, is where the true power lies for the average production artist.I used to be intimidated by MAXScript, too. But then I had a production problem: A client wanted me to model a structure that was covered with tens of thousands of semirandomly oriented panels. A particle system would have been too random, and modeling the panels by hand would have blown the deadline and driven me nuts. My hand was forced; I dove into the MAXScript Reference and tutorials, asked a lot of questions on the discreet MAXScript forum, and, after a couple of days and a lot of wrong turns, had a block of code that did what I needed.The experience opened my eyes to how many repetitive tasks I was doing every day that could be automated with MAXScript. At first I spent as much or more time coding as I saved on tedium, but I soon found opening the Listener and typing a line or two of code as natural as reaching for a modifier or utility, and as essential.Learning MAXScript is really about streamlining your interaction with the program. Knowing a little MXS means being able to communicate with 3ds max in its own language. And, as with any foreign language, knowing even a single phrase at the right time can save you from disaster ("Où se trouve le WC?").We're going to enter the world of MAXScript from both angles: learning how to use interactive MAXScript commands for common tasks, and building a couple of simple utilities to get a taste of what goes into a scripted tool. The chapter is thus divided into two main sections:- "Making Life Interesting" learning a basic MAXScript vocabulary to automate common boring tasks. This section is a primer for those with no MAXScript experience at all, focused on single-line script commands entered in the Listener.
- "Getting Your Way" creating custom UI elements and tools that fit your workflow. This section explores the basics of creating longer scripts, and the use of the Visual MAXScript Editor (VMXS for short) to build interfaces for them.We will build two time-saving scripted utilities in this sectiona draft render settings manager and a replacement for the Color Clipboard utility that docks as a toolbar.
The emphasis in this chapter is on understanding the thought process that goes into planning and writing MAXScript code. The point of this chapter is not to make you a technical director (there are a number of excellent MXS-only training materials available), but rather to put a few simple tools in your hands to help with daily problem solving and workflow trimming. |