[Closed] python COM causing instability
So i have a little app that does stuff with a DB to find a file, then send it to max to open it. The process of sending it to max is fairly simple:
class PyMax(object):
"""Creates a COM connection to 3dsmax"""
def __init__(self):
self.app = win32com.client.Dispatch("MAX.Application.8")
self.app._FlagAsMethod("loadMaxFile")
def load(self, maxFile):
"""This will attempt to load maxFile into 3dsmax"""
try:
self.app.loadMaxFile(maxFile)
return True
except pywintypes.com_error, e:
print e[1]
return False
max = PyMax()
max.load(r"C:\ est.max")
This all works just fine. However i have noticed that i can only do this once or twice before max crashes. Its not always in the same place which makes reproducability a problem. Sometimes i get that little "System exception" error which is always fun.
Has anyone else noticed similar behavior? I'm not sure if i'm missing somethign with the COM connection, like if im supposed to close it handle it differently?
Thanks
I have not had any problems like that before. Let me try the code and see how it goes.
Cheers
Dave
No issue here… other than the standard Max not releasing memory build up while continuously opening files. Are you opening large files or files with rigs in them?
With your code I opened over 300 small scenes before a crash, all under 2 meg. Opening large scenes one after the other never gets too far... throwing in the occasional reset or gc() to clean things up a bit helps...
I didn’t realize you could assign any standard max function to the OLEregister! That’s SWEET… This python stuff is silly walking all over my MaxScript!
yeah, some of the files are large, nothing too crazy though. Maybe i’ll do the gc() after each load.
This is most likely a memory issue (I went through tons when doing batch stuff as well). The safest route is to open a new version of max, process, close, repeat. You shouldn’t have any memory issues this way.
If you are doing small or mixed size files, you could have a counter that holds how many megs have been loaded, and when it crosses a certain point of loaded files (10 files this time, 3 another time, 20 another), close down max and open a new version.