[python-win32] speed up win32com.client
DANIEL POSE
iinjdpa at gmail.com
Sat May 12 21:00:20 CEST 2012
I had tried to change attribute name in several ways (InsertionPoint,
insertionPoint, insertionpoint,...) but I obtained the same error:
Traceback (most recent call last):
File "<ipython console>", line 1, in <module>
File
"C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\startup.py",
line 128, in runfile
execfile(filename, glbs)
File "C:\Documents and Settings\Usuario\Mis
documentos\Dropbox\PYTHON\PruebaAutoCAD.py", line 29, in <module>
M.append(objeto.insertionpoint)
File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line
465, in __getattr__
raise AttributeError("'%s' object has no attribute '%s'" % (repr(self),
attr))
AttributeError: '<win32com.gen_py.AutoCAD 2008 Type Library.IAcadEntity
instance at 0x88940672>' object has no attribute 'insertionpoint'
If I delete only the win32com\client\gen_py folder It doesn't work. I
need delete for example win32com and win32 folders and restore older ones.
2012/5/12 Mark Hammond <skippy.hammond at gmail.com>
> On 10/05/2012 6:38 AM, DANIEL POSE wrote:
>
>> I have read about Early Binding but I hadn't tested the line that you
>> reference:
>> acad= win32com.client.gencache.**EnsureDispatch("AutoCAD.**Application")
>>
>> For my surprise, if I replace line:
>>
>> acad= win32com.client.Dispatch("**AutoCAD.Application")
>>
>> for the line:
>>
>> acad= win32com.client.gencache.**EnsureDispatch("AutoCAD.**Application")
>>
>> I have an error about a missing attribute in the line:
>>
>> M.append(objeto.**InsertionPoint)
>>
>
> Once you use early-binding, the object becomes case sensitive where it
> usually wasn't before. So I suspect you wanted something like
> "insertionPoint" or some other difference in case.
>
>
> The problem here is that if now I go back to use the line:
>>
>> acad= win32com.client.Dispatch("**AutoCAD.Application")
>>
>> Now pywin32 brokes and I have always the same error in line:
>> M.append(objeto.**InsertionPoint)
>>
>> I need to reinstall pywin32 in order to repair the problem.
>>
>
> Yeah, this is unfortunate - once you've generated the early binding
> support, win32com.client.Dispatch will generally be able to use it. A work
> around without reinstalling would have been to delete the
> win32com\client\gen_py directory.
>
> HTH,
>
> Mark
>
>
>>
>>
>> 2012/5/8 Tim Roberts <timr at probo.com <mailto:timr at probo.com>>
>>
>>
>> DANIEL POSE wrote:
>> > Hello,
>> >
>> > I am writing code to program AutoCAD access from Python using
>> pywin32.
>> > When I need to work with a high number of AutoCAD objects, it is
>> > faster to use vba than python.
>> > Are there some way to speed up python code in order to work faster
>> > with AutoCAD elements?
>> > For example in the next code when I work with 512 AutoCAD blocks:
>> > ...
>> >
>> > The output for the code is the following:
>> >
>> > M_dimension= 512
>> > R_dimension= 262144
>> > t_block1= 4.25343304805
>> > t_block2= 3.88635510938
>> > t_block3= 0.487477319045
>> >
>> >
>> > Then it is faster to work with R than M, even though R is bigger.
>> >
>>
>> I hope that's not a surprise to you. The first loop (block2) involves
>> two calls into the AutoCAD COM object in each iteration. The second
>> loop (block3) is simply manipulating lists of integers, entirely within
>> Python.
>>
>> > Some suggestions for speed up pywin32 code in this example?
>> >
>>
>> There isn't really anything here to speed up. You're just "glue". The
>> work is being done in AutoCAD. It is almost impossible for me to
>> believe that Visual Basic does this same loop any faster.
>>
>> However, you can certainly try switching to early binding by using:
>> acad= win32com.client.gencache.**EnsureDispatch("AutoCAD.**
>> Application")
>>
>> --
>> Tim Roberts, timr at probo.com <mailto:timr at probo.com>
>>
>> Providenza & Boekelheide, Inc.
>>
>> ______________________________**_________________
>> python-win32 mailing list
>> python-win32 at python.org <mailto:python-win32 at python.**org<python-win32 at python.org>
>> >
>> http://mail.python.org/**mailman/listinfo/python-win32<http://mail.python.org/mailman/listinfo/python-win32>
>>
>>
>>
>>
>>
>> ______________________________**_________________
>> python-win32 mailing list
>> python-win32 at python.org
>> http://mail.python.org/**mailman/listinfo/python-win32<http://mail.python.org/mailman/listinfo/python-win32>
>>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20120512/6799c94b/attachment.html>
More information about the python-win32
mailing list