mxs_types – MAXScript Datatypes for Development

For an integrated scripting language, MAXScript really is not so bad. It is very powerful for automations within the software and can be used for more generalized tasks on top of that, like reading/writing/moving files,  if you wish to do so. I have seen people implement fully-fledged 2D fluid solvers plus visualization in it (not saying that it is a great idea, but hey, you can!)

However what it seriously lacks are some common data structures that are used in other languages for day-to-day development tasks. The most prominent example for this is the lacking of a dictionary datatype in MAXScript; we can not easily define arbitrary mappings from keys to values. While the underlying C++ SDK has a Hashtable for this, it is (for some mysterious important reason) not exposed to the MAXScript engine.

Dictionaries are just so very versatile, easy to use and provide great lookup performance. Coupled with lists, you can define almost any complex data structure; Just check out the JSON file format, it is simply a combination of lists and dictionaries.

Python has all this, but the current state of the native Python support inside 3ds Max 2015+ is rather disappointing and the Blur guys seem to have abandoned their Py3dsMax project (at least the public version), so that is also not an option. While I hope it will get better in the future, I often find myself knee-deep in MAXScript code until then.

Since there is no builtin solution, people have started writing their own implementations, going from very simple structs that map this to that, to more generalized solutions with more or less better performance. Some examples:

The first example uses an underlying .NET hashtable to implement the dictionary. This provides proper read performance, since we do not have to iterate a list and can use a fast hashvalue-lookup. However, it also limits us to use only strings for both keys and values, since this is the only thing the .NET hashtable understands.

Advertisements

5 Comments

  1. Hi Christoph, this looks really great. And I’m especially impressed by the way you’ve created the entire package on bitbucket together with the tests. I’ve always wanted to do some automated testing for maxscript but never really looked into it. Looking at your tests is a great start! I also like the script you’ve written to build a single scriptfile from multiple ones for easier distribution.

    1. Hey thanks Klaas, much appreciated. It’s the first time I tried readthedocs; There is some overhead involved but I guess it is worth the effort, at least if you have more than one page of documentation or want to show it to people outside of bitbucket/github. I am still thinking if it makes sense to make the whole thing a pip package to be able to download it easily. The maxscript community really needs a hosted package manager 😉

      1. It seems adesk is doing some effort there with the app exchange but it’s a bit half-assed and a nightmare to deploy. Also more recently this site popped up: http://www.3dsmax.ninja. but he “forgot” to ask the script writers permission when he repackaged the tools through his platform.

      2. App exchange looks like a marketplace to me, while I am hoping for a more developer-friendly system like ‘Give me version xyz of library abc and make sure all its dependencies are installed as well’, ideally with the option to install to custom/central locations. Maybe there is an acceptable way to build on top of an existing package manager.

        That ninja thing yes, I appreciate the effort, but the permission thing is definitely a problem.

    2. As for the tests: The current assert thing is pretty ugly, but works. This guy however created a framework for testing in maxscript named maxtest and I have his blessing to take maintainership with a friend, so hopefully we can develop it further. I only did the port to bitbucket so far, no development yet, but we have some plans. Please have a look if you like: maxtest

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.