Sorry!!! my mistake!!! really there are a speed up, the timing using late-binding is:<div><div>M_dimension= 512</div><div>R_dimension= 262144</div><div>t_block1= 3.00059867944</div><div>t_block2= 12.2370913063</div><div>t_block3= 0.488927223991</div>
<div>t_total= 15.7266172097</div></div><div><br></div><div>Then it is about half time using early-binding for my example. It is wonderfull!!</div><div><br><div><br><br><div class="gmail_quote">2012/5/13 DANIEL POSE <span dir="ltr"><<a href="mailto:iinjdpa@gmail.com" target="_blank">iinjdpa@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Just for conclude the discusion, the solution is win32.client.CastTo() as Mark said. However, this modification doesn't speed up the code (at least in my case).<div>
Then, perhaps I need to learn C++ in order to embed python inside AutoCAD as Dan Glassman said. But, not now...</div>
<div>Here I post the code using CastTo:</div><div><br></div><div><code></div><div><br></div><div><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">import win32com.client</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">import time</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">import string</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">import random</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"><br></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">def nombrealeatorio(size=10, chars=string.ascii_uppercase + string.digits):</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"> '''Esta función crea un nombre aleatorio de 10 caracteres'''</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"> return ''.join(random.choice(chars) for x in range(size))</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"> </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">t1=time.clock()</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"><br></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">acad= win32com.client.gencache.EnsureDispatch("AutoCAD.Application")</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">doc=win32com.client.CastTo(acad,"IAcadApplication")</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">doc = acad.ActiveDocument</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">seleccion=win32com.client.CastTo(doc,"IAcadSelectionSets")</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">seleccion=doc.SelectionSets.Add(nombrealeatorio())</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">seleccion=win32com.client.CastTo(seleccion,"IAcadSelectionSet")</p><div class="im">
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">seleccion.SelectOnScreen()</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"><br></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">t2=time.clock()</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">M=[]</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">for objeto in seleccion:</p>
</div><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"> objeto=win32com.client.CastTo(objeto, "IAcadBlockReference")</p><div class="im">
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"> if objeto.ObjectName=='AcDbBlockReference': </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"> M.append(objeto.InsertionPoint)</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">t3=time.clock()</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">print 'M_dimension=',len(M)</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">R=[]</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">for m in M:</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"> for x in M:</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"> R.append(max(m)+max(x))</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">print 'R_dimension=',len(R)</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">t4=time.clock()</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">t_block1=t2-t1</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">t_block2=t3-t2</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">t_block3=t4-t3</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">print 't_block1=',t_block1</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">print 't_block2=',t_block2</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">print 't_block3=',t_block3</p>
</div><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">print 't_total=',t4-t1</p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"><br></p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">
</code></p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"><br></p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">timing using early-binding:</p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">
</p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">M_dimension= 512</p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">R_dimension= 262144</p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">
t_block1= 3.46952811042</p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">t_block2= 4.81084020455</p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">t_block3= 0.49030086226</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">t_total= 8.77066917723</p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"><br></p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">
timing using late-binding:</p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"></p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">M_dimension= 512</p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">
R_dimension= 262144</p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">t_block1= 3.20033803179</p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">t_block2= 4.96431445896</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">t_block3= 0.570101227949</p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">t_total= 8.7347537187</p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">
<br></p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">Thank you for this wonderfull mailing list and pywin32.</p><div><div class="h5"><p></p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">
<br></p><p></p><div class="gmail_quote">2012/5/13 Mark Hammond <span dir="ltr"><<a href="mailto:mhammond@skippinet.com.au" target="_blank">mhammond@skippinet.com.au</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>On 13/05/2012 5:00 AM, DANIEL POSE wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I had tried to change attribute name in several ways (InsertionPoint,<br>
insertionPoint, insertionpoint,...) but I obtained the same error:<br>
<br>
Traceback (most recent call last):<br>
File "<ipython console>", line 1, in <module><br>
File<br>
"C:\Python27\lib\site-<u></u>packages\spyderlib\widgets\<u></u>externalshell\startup.py",<br>
line 128, in runfile<br>
execfile(filename, glbs)<br>
File "C:\Documents and Settings\Usuario\Mis<br>
documentos\Dropbox\PYTHON\<u></u>PruebaAutoCAD.py", line 29, in <module><br>
M.append(objeto.<u></u>insertionpoint)<br>
File "C:\Python27\lib\site-<u></u>packages\win32com\client\__<u></u>init__.py",<br>
line 465, in __getattr__<br>
raise AttributeError("'%s' object has no attribute '%s'" %<br>
(repr(self), attr))<br>
AttributeError: '<win32com.gen_py.AutoCAD 2008 Type Library.IAcadEntity<br>
instance at 0x88940672>' object has no attribute 'insertionpoint'<br>
</blockquote>
<br></div>
In the gen_py directory you should find a generated file supporting the AutoCAD object - it will have a GUID in its name so it might not be obvious which one applies, but inside that you should find the 'IAcadEntity' object. That should have a _prop_map_get attribute which lists the attributes available on the object - I'd expect to find insertionPoint listed there. It may turn out it is actually on a different object, in which case the win32com.client.CastTo() function might be useful to get the appropriate interface.<div>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
If I delete only the win32com\client\gen_py folder It doesn't work. I<br>
need delete for example win32com and win32 folders and restore older ones.<br>
</blockquote>
<br></div>
Hrm - I certainly can't explain that! Or maybe I can - check your %TEMP% folder and see if there is a gen_py directory there?<span><font color="#888888"><br>
<br>
Mark<br>
</font></span></blockquote></div><br></div></div></div>
</blockquote></div><br></div></div>