Bricscad COM API and python win32com

Hello. I'm trying to connect to Bricscad COM API using python win32com. Try adding the line causing the error.
[code]
import win32com.client
acad = win32com.client.Dispatch("BricscadApp.AcadApplication") doc = acad.ActiveDocument model = doc.ModelSpace paper = doc.PaperSpace util = doc.Utility blocks = doc.Blocks print acad, doc,model,paper, util,blocks sCurName = doc.Name # it works print sCurName line = model.AddLine((0,0),(0,10)) # An error occurs
[/code]

Comments


  • import win32com.client
    acad = win32com.client.Dispatch("BricscadApp.AcadApplication")
    doc = acad.ActiveDocument
    model = doc.ModelSpace
    paper = doc.PaperSpace
    util = doc.Utility
    blocks = doc.Blocks
    print acad, doc,model,paper, util,blocks
    sCurName = doc.Name
    print sCurName
    line = model.AddLine((0,0),(0,10))
  • Could it be that :
    model.AddLine((0,0),(0,10))
    is looking for a 3d point?
    model.AddLine((0,0,0),(0,10,0))

  •  line = model.AddLine((0,0,0),(0,10,0)) # cause error
     line = model.AddLine("0,0,0","0,10,0") # it works

    It's weird. In the developer's guide startpoint and endpoint is arraylike variables. In other programs such as Nanocad this code works correctly
    util.GetPoint() return arraylike variable
  • 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.

    from array import array
    import comtypes.client

    acad = comtypes.client.GetActiveObject("BricscadApp.AcadApplication")
    doc = acad.ActiveDocument
    model = doc.ModelSpace
    paper = doc.PaperSpace
    util = doc.Utility
    blocks = doc.Blocks
    print acad, doc,model,paper, util,blocks
    sCurName = doc.Name
    print sCurName
    pnt1 = array('d',(0,0,0))
    pnt2 = array('d',(0,10,0))
    line = model.AddLine(pnt1,pnt2)
  • 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.

  •  I connect to Bricscad COM API using comtypes library. I run the script from the outside.
  • 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

  • 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 python
  • Thanks Akim,  I was running a 32 bit version of Bricscad.  Re-installed it as 64 bit and it works.  Thanks for the advise.
This discussion has been closed.