Hello,<br><br>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).
<br><br>The python code I tested with is:<br><br>[code]<br><br>import win32com.client<br><br>acad = win32com.client.Dispatch("AutoCAD.Application")<br>acad.WindowState = 3<br>acad.Visible = 1<br><br>doc = acad.ActiveDocument
<br>ms = doc.ModelSpace<br>print str(ms.ObjectName)<br>try:<br> ms.AddPoint([0.0, 0.0, 0.0]) # this line gives the problem<br>finally:<br> print "\nTest finished."<br><br>[/code]<br><br>This is the error I got:
<br><br>Traceback (most recent call last):<br> File "<string>", line 65, in run_nodebug<br> File "C:\Programming\Python\Codes\acad_add_point.py", line 11, in ?<br> ms.AddPoint([0.0, 0.0, 0.0
])<br> File "C:\Python24\lib\site-packages\win32com\gen_py\1EFD8E85-7F3B-48E6-9341-3C8B2F60136Bx0x1x1.py", line 12688, in AddPoint<br> ret = self._oleobj_.InvokeTypes(1562, LCID, 1, (9, 0), ((12, 1),),Point<br>
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024809), None)<br><br><br clear="all">python code for AddPoint method from makepy:<br><br># Result is of type IAcadPoint<br>def AddPoint(self, Point=defaultNamedNotOptArg):
<br> """Creates a Point object at a given location"""<br> ret = self._oleobj_.InvokeTypes(1562, LCID, 1, (9, 0), ((12, 1),),Point)<br> if ret is not None:<br> ret = Dispatch(ret, 'AddPoint', '{35AF3AB5-755E-4AC9-8BAF-31B532870751}', UnicodeToString=0)
<br> return ret<br><br><br>And finally, below is the VBA doucumentation provided with AutoCAD.<br><br>Signature <br><br>RetVal = object.AddPoint(Point) <br><br>Object<br><br>ModelSpace Collection, PaperSpace Collection, Block
<br>The object or objects this method applies to. <br><br>Point<br><br>Variant (three-element array of doubles); input-only<br>The coordinates of the point to be created. <br><br>RetVal<br><br>Point object<br>The newly created Point object.
<br><br>Example:<br><br>Sub Example_AddPoint()<br> ' This example creates a point in model space.<br> Dim pointObj As AcadPoint<br> Dim location(0 To 2) As Double<br> <br> ' Define the location of the point
<br> location(0) = 5#: location(1) = 5#: location(2) = 0#<br> <br> ' Create the point<br> Set pointObj = ThisDrawing.ModelSpace.AddPoint(location)<br> ZoomAll<br> <br>End Sub<br><br>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?
<br><br>Thanks a lot for just reading my long message.<br><br>-- <br><br>Regards,<br>- wcc<br><br>