Data Type Problem in Python / COM

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Olav

    #1

    Data Type Problem in Python / COM

    I'm trying to use Python / COM to do some drawing automation. Here
    is a simple code example:
    This code uses a object made by the Opendwg-org. Autocad has a similar
    object with the same methods - and the same result.

    -----------

    import win32com.client
    odaHost=win32co m.client.dynami c.Dispatch("DWG directX.OdaHost App")
    odaApp = odaHost.Applica tion

    point = (0,0,0) #x,y,z

    filename = r'c:\temp\test. dwg'
    odaDoc = odaApp.Document s.Add(filename)

    odaDoc.ModelSpa ce.AddPoint(poi nt)

    --------------

    Traceback (most recent call last):
    File
    "C:\Python24\Li b\site-packages\python win\pywin\frame work\scriptutil s.py",
    line 310, in RunScript
    exec codeObject in __main__.__dict __
    File "F:\dom-users\Autoproje ct\makedwg.py", line 13, in ?
    odaDoc.ModelSpa ce.AddPoint(a)
    File
    "C:\Python24\Li b\site-packages\win32c om\gen_py\2D105 1CA-C44F-4206-A86D-45E24A10ABC7x0x 2x0.py",
    line 9516, in AddPoint
    ret = self._oleobj_.I nvokeTypes(1562 , LCID, 1, (9, 0), ((12,
    1),),Point
    com_error: (-2147352567, 'Exception occurred.', (0, 'DWGdirectX', 'The
    parameter is incorrect.\r\n' , None, 0, -2147024809), None)

    -------------------

    I have tried both early and late binding but with the same result.

    I have seen the same code in VB, and the code looks like this:
    This works.

    ------------

    Sub Example_AddPoin t()
    ' This example creates a point in model space.
    Dim pointObj As AcadPoint
    Dim location(0 To 2) As Double
    ' Define the location of the point
    location(0) = 5#: location(1) = 5#: location(2) = 0#
    ' Create the point
    Set pointObj = ThisDrawing.Mod elSpace.AddPoin t(location)
    ----------------

    It seems to me that this error is related to the data-type
    conversation.
    Any help would be much appreciated

    Thanks
    Olav

Working...