[python-win32] question about COM again: variable type? (wccppp)
drkick16
drkick16 at gmail.com
Mon Dec 12 06:50:23 CET 2005
wccppp,
I too am working on this same issue as we speak. It is my goal to automate
AutoCAD using Python. I've had success using C# (.net) for Automation but I
haven't given up with Python yet. I have done searches here and there on
various search engines and haven't come up with any complete answers on
passing 3 doubles as an array of Variants. This as you see doesn't happen
automatically as it should and Mark has mentioned that idispatch invoke()
manually is the way to correctly pass them. I have yet to master invoke and
all the params. What I need is a working example of Invoke and its
parameters. It seems AutoCAD object model is easy to decifer and the
passing and retrieval of a Variant(s) in Python are my only stepping stones
to complete a successful automation. I am continually monitoring this
mailing list and in my research I will pass on any information that I
uncover.
Drkick16
On 12/11/05, python-win32-request at python.org <
python-win32-request at python.org> wrote:
>
> Send Python-win32 mailing list submissions to
> python-win32 at python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://mail.python.org/mailman/listinfo/python-win32
> or, via email, send a message with subject or body 'help' to
> python-win32-request at python.org
>
> You can reach the person managing the list at
> python-win32-owner at python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Python-win32 digest..."
>
>
> Today's Topics:
>
> 1. question about COM again: variable type? (wccppp)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Sat, 10 Dec 2005 23:30:46 -1000
> From: wccppp <wccppp at gmail.com>
> Subject: [python-win32] question about COM again: variable type?
> To: python-win32 at python.org
> Message-ID:
> <87bd46aa0512110130u70570e7fy4be4b95f5163b1df at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> 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-0001.htm
>
> ------------------------------
>
> _______________________________________________
> Python-win32 mailing list
> Python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
>
>
> End of Python-win32 Digest, Vol 33, Issue 14
> ********************************************
>
--
drkick16
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20051211/c18895ad/attachment.htm
More information about the Python-win32
mailing list