Hello,

I tried using comtypes to change the colors of all objects in the ModelSpace of
a drawing and got some interesting (at least to me) results. First of all, the
speed of Python code is much slower than Autolisp/VisualLisp (a programming
language built into AutoCAD) code. Second of all, I'm puzzled by the significant
differences among different Python methods. 

Python code:

import time
import comtypes.client

app = comtypes.client.GetActiveObject("AutoCAD.Application")
ms = app.ActiveDocument.ModelSpace

def collection(col):
    for elem in col:
        yield elem

print "Starting 1st test..."
timestart = time.clock()
for i in xrange(ms.Count):
    ms.Item(i).Color = 3
timepassed = time.clock() - timestart
print "Done. %.3f seconds passed." % timepassed

print "Starting 2nd test..."
timestart = time.clock()
for obj in collection(ms):
    obj.Color = 3
timepassed = time.clock() - timestart
print "Done. %.3f seconds passed." % timepassed

print "Starting 3rd test..."
timestart = time.clock()
for obj in ms:
    obj.Color = 3
timepassed = time.clock() - timestart
print "Done. %.3f seconds passed." % timepassed

print "Done testing."

Here are some testing results from using Python and Lisp:

----------------------------------------
Processing 7 objects with Python...
Starting 1st test...
Done. 0.030 seconds passed.
Starting 2nd test...
Done. 0.590 seconds passed.
Starting 3rd test...
Done. 0.156 seconds passed.
Done testing.

Processing 7 objects using Lisp...
Done. 0.000 seconds passed.

----------------------------------------
Processing 105 objects with Python...
Starting 1st test...
Done. 0.505 seconds passed.
Starting 2nd test...
Done. 2.871 seconds passed.
Starting 3rd test...
Done. 2.270 seconds passed.
Done testing.

Processing 105 objects using Lisp...
Done. 0.000 seconds passed.

----------------------------------------
Processing 1155 objects with Python...
Starting 1st test...
Done. 5.123 seconds passed.
Starting 2nd test...
Done. 24.918 seconds passed.
Starting 3rd test...
Done. 24.512 seconds passed.
Done testing.

Processing 1155 objects using Lisp...
Done. 0.110 seconds passed.

----------------------------------------
Processing 12705 objects with Python...
Starting 1st test...
Done. 58.586 seconds passed.
Starting 2nd test...
(I stopped the program since it is taking too long.)

Processing 12705 objects using Lisp...
Done. 1.218 seconds passed.

My questions:

1. How can I improve the performance of Python code here? 
2. I suppose comtypes uses early-bound once the module(s) is/are generated in
the comtypes/gen directory? Is this assumption correct? If not, how can I use
early-bound with comtypes? Would that improve the performance?
3. Why would the methods in 2nd and 3rd testing be 5 times slower than the 1st 
one?

Btw, from my testing, the performance of win32com is about the same as comtypes.

Thanks very much for your input!



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users

Reply via email to