python 2.7 - Exception: Invalid object array with comtypes -
i try implement simple copy operation between 2 autocad documents via com in python.
from pyautocad import autocad, apoint comtypes.client import getbestinterface # acad application acad = autocad(create_if_not_exists=true) # create new document doc1 = getbestinterface(acad.application.documents.add()) # add circle in document , make visible circle = getbestinterface(doc1.modelspace.addcircle(apoint(0.0, 0.0), 1.0)) doc1.application.zoomextents() # create document doc2 = getbestinterface(acad.application.documents.add()) # , copy circle new document doc1.copyobjects([circle], doc2.modelspace)
this throws:
traceback (most recent call last): file "copy_bug.py", line 13, in <module> doc1.copyobjects([circle], doc2.modelspace) file "anaconda2\lib\site-packages\comtypes\__init__.py", line 655, in call_with_inout rescode = func(self_, *args, **kw) _ctypes.comerror: (-2145320837, none, (u'invalid object array', u'autocad.application', u'c:\\program files\\autodesk\\autocad 2015\\help\\ole_err.chm', -2145320837, none))
same thing may accomplished in vba with:
dim doc1 acaddocument set doc1 = thisdrawing.application.documents.add dim pt(0 2) double pt(0) = 0#: pt(1) = 0#: pt(2) = 0# dim circ acadcircle set circ = doc1.modelspace.addcircle(pt, 1) thisdrawing.application.zoomextents dim doc2 acaddocument set doc2 = thisdrawing.application.documents.add dim arry(0 0) acadentity set arry(0) = circ doc1.copyobjects arry, doc2.modelspace
i tried numpy arrays, tried casting idispatch
interface, iacadentity
interface , iacadobject
no success (probably silly attempt).
circle = circle.queryinterface(iacadentity)
i tried inside site-packages\comtypes\automation.py
that's above pay grade. setting self.vt
vt_array | vt_dispatch
in _set_value
no suspect problem along lines because, if change dim arry(0 0) acadentity
dim arry(0 0) variant
vba example throw invalid object array
.
i should mention un-commented 2 lines in site-packages\comtypes\automation.py
:
# these not yet implemented: pointer(iunknown): vt_unknown, pointer(idispatch): vt_dispatch,
so .... help?!
meanwhile, there ugly hacks like:
dim doc1 acaddocument set doc1 = thisdrawing.application.documents.add dim pt(0 2) double pt(0) = 0#: pt(1) = 0#: pt(2) = 0# dim circ acadcircle set circ = doc1.modelspace.addcircle(pt, 1) thisdrawing.application.zoomextents dim extmin variant: extmin = thisdrawing.getvariable("extmin") dim extmax variant: extmax = thisdrawing.getvariable("extmax") call thisdrawing.sendcommand( _ "_select window " & cstr(extmin(0)) & "," & cstr(extmin(1)) & _ " " & cstr(extmax(0)) & "," & cstr(extmax(1)) & vbnewline) doc1.sendcommand ("_copybase 0,0" & vbnewline) dim doc2 acaddocument set doc2 = thisdrawing.application.documents.add doc2.sendcommand ("_pasteclip 0,0" & vbnewline)
from pyautocad import autocad, apoint comtypes.client import getbestinterface acad = autocad(create_if_not_exists=true) doc1 = getbestinterface(acad.application.documents.add()) circle = getbestinterface(doc1.modelspace.addcircle(apoint(0.0, 0.0), 1.0)) doc1.application.zoomextents() extmin = doc1.getvariable("extmin") extmax = doc1.getvariable("extmax") doc1.sendcommand( "_select window %f,%f %f,%f\n\r" % ( extmin[0], extmin[1], extmax[0], extmax[1])) doc1.sendcommand ("_copybase 0,0\n\r") doc2 = getbestinterface(acad.application.documents.add()) doc2.sendcommand ("_pasteclip 0,0\n\r")
(of course can create selection set cannot make selection set active; madness)
please post better answer!
Comments
Post a Comment