Home Technical Talk

Scripting streamlines your 3d workflow

polycounter lvl 18
Offline / Send Message
Rick Stirling polycounter lvl 18
I think a lot of 3D artists overlook the power that scripting with their 3D application provides them.

"I'm an artist - so why do I care about scripting?" I hear you cry. Scripts are great for automating repetive tasks, and you don't need to be a programmer to take advantage of them, though if you understand a few of the basic aspects of programming like loops and variables then it becomes even more powerful.

I predominantly use 3d Studio Max at work (along with Silo for modelling), and I've found that maxscript is relatively easy to learn. I'm not a Maya user, but I understand that it's scripting language, Mel, is fantastic.

So how do you start to learn scripting? 3DSMax has a tool called the Maxscript Listener, which records almost everything you do in max. This is usually my first step - I open the listener, then I perform the entire task manually. The listener records all the steps (usually, sometimes the listener has selective hearing), and I can simply copy and paste them to a new script document where I can then edit until I'm content.

How about some examples of where scripting is useful?

I know that all the characters I build in my current project have the same bones, so rather than creating them from scratch each time, I have a script that loads them from an external file. After the bones are loaded, it creates 2 selection sets - 1 for all the bones (but no nubs), and another set with a drastically reduced bone list for the LOD model (no fingers, toes, helper or face bones for example). The script finds all the components that need a skin modifier applied, applies it and assigns the correct bone set - thats the benefit of a sensible naming convention for you.

I like all my renders to look the same, so I've written a render script - it simply loads a scene with my preferred lights, floor and camera, sets the background colour of the scene to be neutral and changes the lighting tint.

Setting up all your shaders? Press a button and maxscript converts all my max materials to shaders, with all the shader values set to our correct defaults.

It's not just 3d applications that can have their workflow improved by scripts - Photoshop is a good example of a 2d package that allows you to create actions to automate repetitive actions - such as resizing and sharpening an entire folder of textures.


I'm working this up into a post for rsart, so any feedback would be great folks. I was thinking of perhaps doing an example of a simple script - would that be useful to anyone? I do quite a lot of scripting, but it's really only basic stuff since we've got tools coders to make all the really complex stuff.

Replies

  • Joao Sapiro
    Options
    Offline / Send Message
    Joao Sapiro sublime tool
    this is something im very interesting of hearing development, since i could really use those kind of scripts but i have no idea how to program them...the only thing i ever programmed was .shader and .ini lol so...thanks rick !
  • Eric Chadwick
    Options
    Offline / Send Message
    More power to you Rick, looking forward to it. Been meaning to dive into MXS for awhile now. I heard the Listener makes crappy code though. At the end of your article you might list the links at the bottom right corner of Scriptspot's page, also maybe the links in the sticky at the top of the MXS forum on CGTalk. I'll probably start there once I get going.
  • Rick Stirling
    Options
    Offline / Send Message
    Rick Stirling polycounter lvl 18
    The maxscript listener code is fine, as long as you take the core of it and wrap it up nicely. Everything in the listener is written specifically for the objects that it is dealing with at the point, so I normally add a layer of abstraction.

    A simple script that I use a lot is rotating a character. I build my characters facing forwards - so that the front view in max is the front of my character. For reason (I suspect legacy code or tools), the characters have to be facing away from you for export. If this was something that was done once, it'd be fine, but you might be spinning the character a lot between editing, exporting, editing, exporting etc.

    Manually you have to go to the front view to decide if the character is in the right orientation for your task, select a bone, put the model into figure mode, go to the character studio rotate root button, then rotate it 180 degrees.

    None of that is hard to do, but it takes 15-20 seconds and it's not exactly creative.

    My script has two buttons, "Edit mode" and "Export Mode". They both do the same thing, so I was clever enough to use functions, but essentially you press a button then:

    It selects the root bone(always the same name in every model) and puts the model into figure mode. This means you don't have to search for a bone, which can be a pain in heavy scenes.

    It gets the X position of the left foot. Why? Well, if the position of the left foot is positive, then the model is facing forwards. If it is negative, then the model is facing away from you.

    It rotates the figure either 0 degrees or 180 degrees, depending on what orientation you want it to be in. The reason I do this is that it's simpler to always call the rotate function and make it rotate 0 degrees than it is to put in a check to see if it needs to.
  • Ruz
    Options
    Offline / Send Message
    Ruz polycount lvl 666
    I am toying with learning maxscript Rick, just haven't had the courage yet to really go for it
  • ElysiumGX
    Options
    Offline / Send Message
    ElysiumGX polycounter lvl 18
    scripting in Python is so easy to learn, and I recommend it as a learning tool for script writing.
  • Rick Stirling
    Options
    Offline / Send Message
    Rick Stirling polycounter lvl 18
    Ruz - go for it. The best thing to do is to pick a simple task and try to script it. I learned to script not by doing abstract examples, but by just grabbing the bull by the horns and trying to write something useful.

    Ely - Python is all well and good (as is Lua), but it's not Mel or Maxscript so it doesn't really have a practical application when it coms to scripting (apart from making you hate how cobbled together some of maxscript is)
  • Rick Stirling
    Options
    Offline / Send Message
    Rick Stirling polycounter lvl 18
  • tacit math
    Options
    Offline / Send Message
    tacit math polycounter lvl 17
    for the maya users. as far as modelling goes this is maybe the most useful script i've put together ( with the help of a guy name of john homer ) :

    http://orderindebris.exorsus.net/misc/jkbFlattenVerts_2.1.rar

    it'll average the position of a bunch of verts on a specified axis. or snap them to a given location. pretty handy. use it all the time. straight out of the box maya feels pretty heavy. but once you've learned a little MEL and have your shelves set with all sorts of custom shit and workflow enhancements she's a kitten

    .
  • ElysiumGX
    Options
    Offline / Send Message
    ElysiumGX polycounter lvl 18
    [ QUOTE ]
    Ely - Python is all well and good (as is Lua), but it's not Mel or Maxscript so it doesn't really have a practical application

    [/ QUOTE ]

    Oh, I understand. But Python is implemented as a scripting language for some 3D design software. So there's no need for learning cobbled program specific languages. With that in mind, it would be easier for find Python scripters and tutorials, and it's a cool language to start with if you're not experienced with programming.
  • Jesse Moody
    Options
    Offline / Send Message
    Jesse Moody polycounter lvl 17
    I agree with you Rick that not enough 3d artists know enough about scripting and how it can really help improve / speed workflow. I tend to be a max user but have learned MEL over the past year and half and have made some pretty handy stuff. Learning a little about loops and procedures can help you make a lot of handy tools.

    I have also customized my maya to act more like max with it's poly modeling tools and customizing the shelves.
  • James Edwards
    Options
    Offline / Send Message
    James Edwards polycounter lvl 18
    I'm heavy into jscript for XSI right now... all my custom tools are written in jscript. I do plan on porting some of the bigger ones to python though, as it is nicely integrated into xsi and a growing number of other packages.
  • IronHawk
    Options
    Offline / Send Message
    IronHawk polycounter lvl 10
    Python and C# are next on my list.

    Scripting is a tremendous help in just about every application I can think of. It's hard to explain just how much time it saves until you start using scripts/macros. I think a lot of people get used to there flow and feel there fast enough so they put it off.

    I also use a program called Autohotkey. Its a scriptable macro tool with recorder. Its freeware and opensource.
  • Jesse Moody
    Options
    Offline / Send Message
    Jesse Moody polycounter lvl 17
    Oh yeah I forgot to mention. I am not sure how many of you have already heard this but Maya 8.5 will feature Python as well. Should open up some nice stuff for tool development in Maya.
Sign In or Register to comment.