[python-win32] question about COM again: variable type?

wccppp wccppp at gmail.com
Sun Dec 11 10:30:46 CET 2005


Hello,

I'm having problem implementing a "AddPoint" method in AutoCAD.  From the
search I've done,  seems the problem is variable type: I supplied a list as
the x,y,z coordinates of a point, why seems what is expected is a Variant
(three-element array of doubles).

The python code I tested with is:

[code]

import win32com.client

acad = win32com.client.Dispatch("AutoCAD.Application")
acad.WindowState = 3
acad.Visible = 1

doc = acad.ActiveDocument
ms = doc.ModelSpace
print str(ms.ObjectName)
try:
    ms.AddPoint([0.0, 0.0, 0.0])   # this line gives the problem
finally:
    print "\nTest finished."

[/code]

This is the error I got:

Traceback (most recent call last):
  File "<string>", line 65, in run_nodebug
  File "C:\Programming\Python\Codes\acad_add_point.py", line 11, in ?
    ms.AddPoint([0.0, 0.0, 0.0])
  File "C:\Python24\lib\site-packages\win32com\gen_py\1EFD8E85-
7F3B-48E6-9341-3C8B2F60136Bx0x1x1.py", line 12688, in AddPoint
    ret = self._oleobj_.InvokeTypes(1562, LCID, 1, (9, 0), ((12, 1),),Point
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None,
None, 0, -2147024809), None)


python code for AddPoint method from makepy:

# Result is of type IAcadPoint
def AddPoint(self, Point=defaultNamedNotOptArg):
    """Creates a Point object at a given location"""
    ret = self._oleobj_.InvokeTypes(1562, LCID, 1, (9, 0), ((12, 1),),Point)
    if ret is not None:
        ret = Dispatch(ret, 'AddPoint',
'{35AF3AB5-755E-4AC9-8BAF-31B532870751}', UnicodeToString=0)
    return ret


And finally, below is the VBA doucumentation provided with AutoCAD.

Signature

RetVal = object.AddPoint(Point)

Object

ModelSpace Collection, PaperSpace Collection, Block
The object or objects this method applies to.

Point

Variant (three-element array of doubles); input-only
The coordinates of the point to be created.

RetVal

Point object
The newly created Point object.

Example:

Sub Example_AddPoint()
    ' 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.ModelSpace.AddPoint(location)
    ZoomAll

End Sub

Sorry for the long post.  I've actually spent more than 2 or 3 hours
searching the web for an answer.  And I did see lots of discussions related
to this sort of issue: safearray, variant array, etc..  But I didn't see a
definite answer.  More than likely it is because I'm a beginner in Python
and could not make sense out of those discussion.  Can someone elaborate a
little bit on this?

Thanks a lot for just reading my long message.

--

Regards,
- wcc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20051210/f1dca702/attachment.htm


More information about the Python-win32 mailing list