Python + MXS


Hi Martin,

The wiki page is great idea I will add some examples later this week.



Thanks Dave. I just bought Mark Lutz’s books today to finally get my head around the whole thing properly. :slight_smile:


Mark Lutz’s books are really good I have two of them on my desk all the time… I also like Core Python by Wesley Chun.




I have just tried to make smth in max via python but when i try to dispatch max application i get something like this:
code in python:

import win32com.client
conn = win32com.client.Dispatch(“MAX.Application.8”)

and when i evaluate it i get:
Traceback (most recent call last):
File “C:/Python25/1”, line 5, in <module>
conn = win32com.client.Dispatch(“MAX.Application.8”)
File “C:\Python25\Lib\site-packages\win32com\”, line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File “C:\Python25\Lib\site-packages\win32com\client\”, line 98, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File “C:\Python25\Lib\site-packages\win32com\client\”, line 78, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
com_error: (-2147221005, ‘\xcd\xe5\xe4\xee\xef\xf3\xf1\xf2\xe8\xec\xe0\xff \xf1\xf2\xf0\xee\xea\xe0 \xf1 \xf3\xea\xe0\xe7\xe0\xed\xe8\xe5\xec \xea\xeb\xe0\xf1\xf1\xe0’, None, None)

i ran it under python 2.5 with win32 module installed
what am i doing wrong??


Hi CyHiSo,

Did you register the com service from max?



yes.i ran that script. but, it seems to me that there is some other problem.i can’t understand why python returns error when im trying to dispatch it with
conn = win32com.client.Dispatch(“MAX.Application.8”)?


Are you running Vista bychance?

If so, you might try disabling User Account Control (UAC). That’s a known source of mysterious COM failures.


Has anyone tried getting the Com to work with mutliple instances of max running?


No.I’m runnin’ XP SP2


Yes, it only works when max is calling a COM object. If you are calling maxes com server the most recently opened max takes focus, I have not found a solution to this problem (yet).



Did you register the maxes COM server while logged in with Admin rights? I have found that if you register the com server without admin rights you will (may) get an error.



I’m going to put my hand up to claim total ignorance about how binary data is parsed, so take this question in that light:

I’m looking to mine .max files for their internal data (such as textures, poly counts etc) so I can set up a file browser that gives a detailed description of the contents.

Has anyone done this before? My knowledge of file reads has been limited to ascii data in the past, so i’m trying to work out if I need to use some sort of struct read or unpack to bring in the max file information to search and pull out the correct values. That’s pretty much where my brick wall starts!

This is a purely external python project. I want to be able to mine max files without accessing the max runtime at all.


I personally doubt this will be possible as .max files are proprietary entities handled by 3ds Max’s routines. It might be possible through SDK, but still, if it was this case, the format would eventually become open-source by the community and therefore would break Autodesk’s many intentional limitations.

You could, possible, then open the .max file in Maya or XSI or what not, which’d be awesome, but also allow you to open .max files saved in Max 2009 in Max 8 for example, which is intentionally being prohibited by Autodesk.

But this is purely my own speculation, might be possible, but who knows :slight_smile:


Wasn’t there a 3d viewer which registered a com object or plugin and with that enabled the viewer to view max files? From what I understand from the max binairy files is that alot of data is stored in data blocks, which can be any type of data a plugin wants. So with that it’s hard too convert too ascii since a lot of data is binairy… but that’s just what I’ve understand from reading some comments somewhere… I think if autodesk could easy make it ascii they would have done it long time already… everyone wants this badly…



You might want to have a look at MaxFileReader ( It is a standalone tool to get information from max files. It is not written in Python though (C++).


I doubt they’ll ever do this as that’d allow for opening the scenes in older versions of Max, which is what Autodesk doesn’t want no matter what they say :wink: Also, that’d open the format for 3rd parties.

Don’t know, but I think it’s never gonna happen.


I don’t think it would be impossible, it would just require allot of reverse engineering. I recall the C++ example but I have been unable to get it to read a file with out issue. If it could be done through SDK I guess you could get a command line tool going that spits out XML or something. It would awesome to be able to do this though. I will have a look through the SDK docs to see if anything pops up.



Thanks Marcus, that looks promising. I may be able to integrate parts of it.

It’s interesting that if you open a .max file in notepad you can actually extract key information such as textures used, shaders and so forth. Each character is separated with a null, but it may be possible to glean information via an ascii read by doing some clever searching or regular expressions.

I do tend to agree with loocas. For ages it wasn’t in Autodesk’s best interests to have an ascii/XML format, but the way things are leaning now, it would be crazy for them not to.

Imagine how much more of a joy delta versioning and file manipulation would be! :smiley:


Just like in max, we use it via COM. As mentioned in Kermit’s link, its the same as VBS. We use it for a variety of things like launching scripts, saving stuff to the DB, etc. Its really good for having a floating non-modal window for photoshopping :slight_smile:


The reason for strings having those “nulls” may come from MAX using a wide character format like Unicode or another multibyte format to save out image paths. This is necessary to support paths that contain characters which are not in the original ASCII character set.

So actually you would not have to make a search for ASCII strings but for those unicode strings. I havent been into Python very deep as of now but as far as I know it supports unicode strings. Having said that, I do not think it might be a good idea to make a brute force search on the binary file on those strings since you dont know what purpose those strings have. Generating a “bridge” via the sdk might be the safer method.