Notifications
Clear all

[Closed] Python + MXS

Hi,everybody!

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\client_init_.py”, line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File “C:\Python25\Lib\site-packages\win32com\client\dynamic.py”, line 98, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File “C:\Python25\Lib\site-packages\win32com\client\dynamic.py”, 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?

Cheers
Dave

1 Reply
(@cyhiso)
Joined: 10 months ago

Posts: 0

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.

3 Replies
(@cyhiso)
Joined: 10 months ago

Posts: 0

No.I’m runnin’ XP SP2

(@specxor)
Joined: 10 months ago

Posts: 0

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.

Cheers
Dave

(@cyhiso)
Joined: 10 months ago

Posts: 0

Hi!
if u mean pressing “Register” button in COM/DCOM Server Control Utility – I did so.But i get:

File “C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py”, line 309, in RunScript
debugger.run(codeObject, main.dict, start_stepping=0)
File “C:\Python25\Lib\site-packages\pythonwin\pywin\debugger_init_.py”, line 60, in run
GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
File “C:\Python25\Lib\site-packages\pythonwin\pywin\debugger\debugger.py”, line 624, in run
exec cmd in globals, locals
File “C:\Python25\Script1.py”, line 2, in <module>
conn = win32com.client.Dispatch(“MAX.Application.8”)
File “C:\Python25\Lib\site-packages\win32com\client_init
.py”, line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File “C:\Python25\Lib\site-packages\win32com\client\dynamic.py”, line 98, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File “C:\Python25\Lib\site-packages\win32com\client\dynamic.py”, line 78, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
com_error: (-2147221005, ‘Invalid class string’, None, None)

again and again…what am i supposed to do?

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

1 Reply
(@specxor)
Joined: 10 months ago

Posts: 0

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).

Cheers
Dave

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.

1 Reply
(@loocas)
Joined: 11 months ago

Posts: 0

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

 JHN

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…

-Johan

1 Reply
(@loocas)
Joined: 11 months ago

Posts: 0

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 Also, that’d open the format for 3rd parties.

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

You might want to have a look at MaxFileReader ( http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=7481504 ). It is a standalone tool to get information from max files. It is not written in Python though (C++).

2 Replies
(@erilaz)
Joined: 11 months ago

Posts: 0

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!

(@relief7)
Joined: 11 months ago

Posts: 0

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.

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.

Cheers
Dave

David, did you ever post this example? I’m looking at some networked functionality and thought your app might be a useful resource.

Hi erilaz,

Yeah I did and it worked really well. I will post the code shortly, all of the networking was handled by pyro.

Cheers
Dave

2 Replies
(@erilaz)
Joined: 11 months ago

Posts: 0

Thanks, that will be helpful. Incidently, are you the same Dave that went to Mad Academy? I assume it’s not coincidence.

(@erilaz)
Joined: 11 months ago

Posts: 0
Page 15 / 26