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). Then, perhaps I need to learn C++ in order to embed python inside AutoCAD as Dan Glassman said. But, not now... Here I post the code using CastTo:
<code> import win32com.client import time import string import random def nombrealeatorio(size=10, chars=string.ascii_uppercase + string.digits): '''Esta función crea un nombre aleatorio de 10 caracteres''' return ''.join(random.choice(chars) for x in range(size)) t1=time.clock() acad= win32com.client.gencache.EnsureDispatch("AutoCAD.Application") doc=win32com.client.CastTo(acad,"IAcadApplication") doc = acad.ActiveDocument seleccion=win32com.client.CastTo(doc,"IAcadSelectionSets") seleccion=doc.SelectionSets.Add(nombrealeatorio()) seleccion=win32com.client.CastTo(seleccion,"IAcadSelectionSet") seleccion.SelectOnScreen() t2=time.clock() M=[] for objeto in seleccion: objeto=win32com.client.CastTo(objeto, "IAcadBlockReference") 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 print 't_total=',t4-t1 </code> timing using early-binding: M_dimension= 512 R_dimension= 262144 t_block1= 3.46952811042 t_block2= 4.81084020455 t_block3= 0.49030086226 t_total= 8.77066917723 timing using late-binding: M_dimension= 512 R_dimension= 262144 t_block1= 3.20033803179 t_block2= 4.96431445896 t_block3= 0.570101227949 t_total= 8.7347537187 Thank you for this wonderfull mailing list and pywin32. 2012/5/13 Mark Hammond <mhamm...@skippinet.com.au> > On 13/05/2012 5:00 AM, DANIEL POSE wrote: > >> 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' >> > > 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. > > > 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. >> > > 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? > > Mark >
_______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32