[python-win32] speed up win32com.client

DANIEL POSE iinjdpa at gmail.com
Sun May 13 13:42:24 CEST 2012


Thank you Dan, by now it is clear for me. Unfortunately I haven't C++
knowledge but don't worry, for me it is enought to know that the problem is
not in python or in my code.
Now I am occasionaly programmer in Python or VBA, then it would be too
complicated for me to learn C++, but perhaps I will consider this question
in the future.

2012/5/12 Dan Glassman <dan.glassman at gmail.com>

> VBA is faster because it's running in-process inside AutoCAD (everything
> is loaded into acad.exe).  Python runs out-of-process (AutoCAD objects need
> to be passed back and forth between acad.exe and python.exe).
>
> You can use AutoCAD's ObjectARX API to embed python inside AutoCAD and
> make python in-process; you'll get a significant speedup.  You'll need to
> know C++ in order to do that.  Let me know if you'd like further details.
>
> 64-bit AutoCAD runs VBA out-of-process because there is no 64-bit VBA;
> you'd see the same slowness there that you're seeing with python.
>
> -drg
>
>
>
> On Mon, May 7, 2012 at 5:26 PM, DANIEL POSE <iinjdpa at gmail.com> 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:
>>
>> import win32com.client
>>
>> import time
>>
>> t1=time.clock()
>>
>> acad= win32com.client.Dispatch("AutoCAD.Application")
>>
>> doc = acad.ActiveDocument
>>
>> seleccion=doc.SelectionSets.Add('selection6')
>>
>> seleccion.SelectOnScreen()
>>
>> t2=time.clock()
>>
>> M=[]
>>
>> for objeto in seleccion:
>>
>> if objeto.ObjectName=='AcDbBlockReference':
>>
>> M.append(objeto.InsertionPoint)
>>
>> t3=time.clock()
>>
>> print 'M_dimension=',len(M)
>>
>> R=[]
>>
>> for m in M:
>>
>> for x in M:
>>
>> R.append(max(m)+max(x))
>>
>> print 'R_dimension=',len(R)
>>
>> t4=time.clock()
>>
>> t_block1=t2-t1
>>
>> t_block2=t3-t2
>>
>> t_block3=t4-t3
>>
>> print 't_block1=',t_block1
>>
>> print 't_block2=',t_block2
>>
>> print 't_block3=',t_block3
>>
>>
>> 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.
>>
>> Some suggestions for speed up pywin32 code in this example?
>>
>>
>> Best Regards,
>>
>> Daniel Pose.
>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> python-win32 mailing list
>> python-win32 at python.org
>> http://mail.python.org/mailman/listinfo/python-win32
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20120513/db2f0fa3/attachment.html>


More information about the python-win32 mailing list