MAXScript part of duberPython

duberPython can be called by its name "dPy" in MAXScript and contains a few useful methods that can be used to either manage duberPython itself, or call the IronPython engine and executes whatever you pass it.

dPy.run <string>

this is the most basic way to get a Python script executed and have IronPython return the results back to MAXScript. For example, to get the number Pi from the Python's standard math library, run this code:

dPy.run @"import math
mxsCon.setResult(math.pi)"

what you get in MAXScript is the correct, floating point value of 3.14159

dPy.runFromFile <string> <array>

probably the most useful way of using duberPython is to call the .runFromFile method and pass it a Python script file and an array of variables. The variables will get translated properly to Python, so you don't have to worry about wrapping anything in quotes, or the likes. So, in order to demonstrate this, write a Python script and call it a maxTest.py. Put this code inside:

mxsCon.setResult(mxsCon.args)

then in MAXScript call the script this way:

dPy.runFromFile @"path\to\maxTest.py" args:#("string", 123, True, undefined, #("secondary", "array"))

you'll get the exact same arguments back in MAXScript, which confirms that the data types got translated correctly from MAXScript to Python and back.

dPy.resetPy()

this method will reset the current duberPython session, meaning it will clear all the memory from the variables, temporary data etc... so you can start with a clean plate.

dPyUtils.register <string>

this method will allow you to register a purchased license of duberPython. Simply pass it the registration key you'll receive in the confirmation e-mail and it'll register the license for you.

dPyUtils.uninstall()

use this method to completely get rid of duberPython on your system. It might leave a few, read-only, files on your file system, but duberPython will not run again after you restart 3ds Max. If you want to completely delete all the files duberPython had installed on your system, look into the stdplugs folder and delete the IronPython folder when Max is not running.

Python part of duberPython

We've implemented an object called "mxsCon" (no quotes) within duberPython so that you can communicate with MAXScript while executing commands from Max in Python. This object has a few methods and a few properties that are very helpful in this two-way communication bridge.

mxsCon.args

this object stores any arguments sent from MAXScript via calling the dPy.runFromFile method. You can access them as you would sys.argv

mxsCon.setResult <object>

this method will push the passed object (a variable) to MAXScript. For example:

mxsCon.setResult(sys.path)

will print all the system paths in the current Python session in MAXScript.

mxsCon.getResult()

this method will only return the last passed object to MAXScript.

mxsCon.execute <string>

this method will thake the string and try to execute it in MAXScript. For example:

mxsCon.execute '10 * 20'

will return 200
The .execute() method works similarly like the .format() method in Python so that you can pass it various arguments more conveniently. For example:

mxsCon.execute( 'myMaxscriptFn( {0}, {1}, {2}, {3} )', (0,1,2), {x=1, y=True, z=['text', true]}, 15, false )

This will first parse the string properly, then will try to execute it in MAXScript.

mxsCon.convert <expr>

This method will convert the variable or expression to a string and then will pass it to MAXScript for further processing. This way you can preserve the original data type notation from Python. Similar to what pprint does.