Bricscad COM API and python win32com
Comments
-
import win32com.clientacad = win32com.client.Dispatch("BricscadApp.AcadApplication")doc = acad.ActiveDocumentmodel = doc.ModelSpacepaper = doc.PaperSpaceutil = doc.Utilityblocks = doc.Blocksprint acad, doc,model,paper, util,blockssCurName = doc.Nameprint sCurNameline = model.AddLine((0,0),(0,10))0
-
Could it be that :
model.AddLine((0,0),(0,10))
is looking for a 3d point?
model.AddLine((0,0,0),(0,10,0))0 -
line = model.AddLine((0,0,0),(0,10,0)) # cause errorline = model.AddLine("0,0,0","0,10,0") # it worksIt's weird. In the developer's guide startpoint and endpoint is arraylike variables. In other programs such as Nanocad this code works correctlyutil.GetPoint() return arraylike variable0
-
The problem was with the type of the array. Bricscad requires an array type VT_ARRAY | VT_R8. Python lists do not match this type. This problem is solved with the creation of the array of the appropriate type in python by the command array('d', >).win32com replaced by comtypes library.import comtypes.clientacad = comtypes.client.GetActiveObject("BricscadApp.AcadApplication")doc = acad.ActiveDocumentmodel = doc.ModelSpacepaper = doc.PaperSpaceutil = doc.Utilityblocks = doc.Blocksprint acad, doc,model,paper, util,blockssCurName = doc.Nameprint sCurNamepnt1 = array('d',(0,0,0))pnt2 = array('d',(0,10,0))line = model.AddLine(pnt1,pnt2)0
-
Hello all,
How do you implement your code in Bricscad? I have been working strictly in Lisp thus far, and have some Python experience and love the language. Sounds interesting.
0 -
I connect to Bricscad COM API using comtypes library. I run the script from the outside.0
-
I get this error when trying to access Bricscad from the Python Shell. I have imported comtypes.client and I have Bricscad running.
>>> acad=comtypes.client.GetActiveObject("BricscadApp.AcadApplication")
Traceback (most recent call last):
File "", line 1, in
acad=comtypes.client.GetActiveObject("BricscadApp.AcadApplication")
File "C:\Python34\lib\site-packages\comtypes\client\__init__.py", line 180, in GetActiveObject
obj = comtypes.GetActiveObject(clsid, interface=interface)
File "C:\Python34\lib\site-packages\comtypes\__init__.py", line 1238, in GetActiveObject
oledll.oleaut32.GetActiveObject(byref(clsid), None, byref(p))
File "_ctypes/callproc.c", line 920, in GetResult
OSError: [WinError -2147221021] Operation unavailable
>>>Any ideas on what will cause this error?
Thanks,
Kevin
0 -
I get this error when trying to access Bricscad from the Python Shell. I have imported comtypes.client and I have Bricscad running.
>>> acad=comtypes.client.GetActiveObject("BricscadApp.AcadApplication")
Traceback (most recent call last):
File " ", line 1, in
acad=comtypes.client.GetActiveObject("BricscadApp.AcadApplication")
File "C:\Python34\lib\site-packages\comtypes\client\__init__.py", line 180, in GetActiveObject
obj = comtypes.GetActiveObject(clsid, interface=interface)
File "C:\Python34\lib\site-packages\comtypes\__init__.py", line 1238, in GetActiveObject
oledll.oleaut32.GetActiveObject(byref(clsid), None, byref(p))
File "_ctypes/callproc.c", line 920, in GetResult
OSError: [WinError -2147221021] Operation unavailable
>>>Any ideas on what will cause this error?
Thanks,
Kevin
Perhaps you're trying to connect to a 64 bit version of Bricscad. For this you need a 64 bit version comtypes and python0 -
Thanks Akim, I was running a 32 bit version of Bricscad. Re-installed it as 64 bit and it works. Thanks for the advise.0