[Closed] creatOLEObject: can't create instance
Hi,
I am trying to consume a Pythoncom server from Maxscript. I need this to be able to call some mysql queries in python script from maxscript. I tried to follow the steps in this article.
I created a small pythoncom server
import sys, os
def getWorkingDirectory() :
return os.path.dirname(sys.argv[0])
sys.path.append('tubeBDD')
from Database import Database
import selectBDD as select
db = Database()
# A simple Python COM server.
class PythonComUtilities:
_public_methods_ = ['getProjects']
_reg_progid_ = 'PythonCom.Utilities'
# Class ID must be new/unique for every server you create
_reg_clsid_ = '{BAC62D37-EEDF-46B3-8DED-11E842225B0E}'
def getProjects(self, string):
# self.db = Database()
projects = select.getProjects(db)
proj = ""
for p in projects:
if proj == "":
proj = p[0]
else:
proj = proj + "," + p[0]
return proj
if (__name__ == '__main__'):
print 'Registering COM server...'
import win32com.server.register as comReg
comReg.UseCommandLine(PythonComUtilities)
Then I try to call it in a maxscript :
comObj = createOLEObject "PythonCom.Utilities"
It gives me this error :
-- Runtime error: createOLEObject: can't create instance PythonCom.Utilities
Any idea what I’m doing wrong ?
Hi,
trying to bring up the subject as I am realy stuck on it, and I really need to get it working!
Hi Johanna,
this is rather question related to Python than Max script, and maybe for that you has not get response. Your Max script part is ok.
At the Python code I can’t help ’cause am too far away from this language, but I have some pure logical assumption that all the code on top of your script (added before the class definition) are lost in reg-process ’cause it is out of the class, and this is probably the reason of failing when you try to create an instance of your component. (Just to repeat – I make guesses only)
Well, first of all I’m curious why you need to register new component to work with databases in Max. You can do that using ADODB via DotNet or directly with createOLEObject(). There is a SQL example in the help on “SafeArrayWrapper Class” page. Also Ofer Zelichover wrote a tutorial especially for working with MySQL in MaxScript: http://www.oferz.com/Tutorials/tutMySQLConnector.html
I never try it out though ’cause I never need MySQL but worth the look.
I’m sure you’ll get more help here on that part if you need.
Thanks for your interest,
I had found this article, but somehow I couldn’t get it to work either. But I’ll try to dig into that again as I am indeed using mysql, I can’t use ADODB.
I tried to put the code on top of my script inside my class definition, but it didn’t change anything…
I had trouble installing the connector, but now everything works fine using dotNet
Thanks