Just a quick useful snippet - occasionally it can be necessary to be able to call out to the command line from Maxscript for some task. This might be to run a Python script that atlases a folder of images you’ve just batch rendered, or a script that uploads asset data to your companies Shotgun database… etc. There are a whole bunch of reasons you might find you need to do this given the relative limitations of Maxscript.
The two (roughly equivalent) functions we’re interested in being
HiddenDOSCommand (doc link). The limitation we have is that any output from our actions at the command prompt are lost and all we’re left with in Max is an integer error code.
But if we use the dotNetObject “System.Diagnostics.Process” instead, we can redirect any output or errors from the command line back to be handled in Maxscript. I’ve not used that much dotNet in Maxscript so far, so this is a pretty simple implementation and I won’t go into details. All the code for an alternative to
DOSCommand is below.
This runs a script or executable from the command prompt with an optional array of string arguments. (format these as for the command line) The script will capture any command prompt output (including errors) and return it as an array of strings to Maxscript (or optionally returned as a single string with newline and return characters).