Open a new instance of Autocad via Python -
does have experience using python autocad? i'm trying, test see if can open new instance of autocad via python , though pyautocad worked (feel free offer other suggestions, if have any)
anyway based on doc (https://pypi.python.org/pypi/pyautocad/#downloads) - says these lines of code should it, nothing's happened of yet.
pyautocad import autocad, apoint acad = autocad() acad.prompt("hello, autocad python\n"
just these lines of code should generate info on commandline instead results in 50 lines worth of traceback (which can post if anyone's interested) - ideas?
traceback (most recent call last): file "<pyshell#5>", line 1, in <module> acad.prompt("hello, autocad") file "c:\python27\lib\site-packages\pyautocad\api.py", line 153, in prompt self.doc.utility.prompt(u"%s\n" % text) file "c:\python27\lib\site-packages\pyautocad\api.py", line 65, in doc return self.app.activedocument file "c:\python27\lib\site-packages\pyautocad\api.py", line 54, in app self._app = comtypes.client.getactiveobject('autocad.application') file "c:\python27\lib\site-packages\comtypes\client\__init__.py", line 180, in getactiveobject obj = comtypes.getactiveobject(clsid, interface=interface) file "c:\python27\lib\site-packages\comtypes\__init__.py", line 1165, in getactiveobject oledll.oleaut32.getactiveobject(byref(clsid), none, byref(p)) file "_ctypes/callproc.c", line 941, in getresult windowserror: [error -2147221021] operation unavailable
after adding vba module, traceback reads:
traceback (most recent call last): file "<pyshell#4>", line 1, in <module> acad.prompt("hello") file "c:\python27\lib\site-packages\pyautocad\api.py", line 153, in prompt self.doc.utility.prompt(u"%s\n" % text) file "c:\python27\lib\site-packages\pyautocad\api.py", line 65, in doc return self.app.activedocument file "c:\python27\lib\site-packages\pyautocad\api.py", line 54, in app self._app = comtypes.client.getactiveobject('autocad.application') file "c:\python27\lib\site-packages\comtypes\client\__init__.py", line 183, in getactiveobject return _manage(obj, clsid, interface=interface) file "c:\python27\lib\site-packages\comtypes\client\__init__.py", line 188, in _manage obj = getbestinterface(obj) file "c:\python27\lib\site-packages\comtypes\client\__init__.py", line 112, in getbestinterface interface = getattr(mod, itf_name) attributeerror: 'module' object has no attribute 'iacadapplication'
now after deleting comtypes' "gen" folder per @reclosedev, autocad opens string of text still not appear on command line - traceback reads:
traceback (most recent call last): file "<pyshell#4>", line 1, in <module> acad.prompt("hello") file "c:\python27\lib\site-packages\pyautocad\api.py", line 153, in prompt self.doc.utility.prompt(u"%s\n" % text) file "c:\python27\lib\site-packages\pyautocad\api.py", line 65, in doc return self.app.activedocument file "c:\python27\lib\site-packages\pyautocad\api.py", line 59, in app self._app.visible = self._visible file "c:\python27\lib\site-packages\comtypes\client\dynamic.py", line 116, in __setattr__ dispid = self._comobj.getidsofnames(name)[0] file "c:\python27\lib\site-packages\comtypes\automation.py", line 643, in getidsofnames self.__com_getidsofnames(riid_null, arr, len(names), lcid, ids) comerror: (-2147418111, 'call rejected callee.', (none, none, none, 0, none))
have considered ironpython?
here's quick example of how leveraged:
import clr import system system import type, activator acapp = activator.createinstance(type.gettypefromprogid("autocad.application")) acapp.visible = 1 acapp.activedocument.sendcommand("(princ \"hello world python!\")(princ)\n")
obviously progid correspond whichever version of autocad opened last.
Comments
Post a Comment