[python-win32] problem AddLine AutoCAD win32com.client
Mark Hammond
mhammond at skippinet.com.au
Wed Feb 1 23:13:07 CET 2012
Re-added the python-win32 list - please keep replies on list.
Your code uses:
> pt1 = array.array('d', [0.0,0.0,0.0])
> pt2=array.array('d',[1.0,1.0,__0.0])
But these aren't supported by pywin32 in the way you expect - what
happens if you change this to:
pt1 = [0.0,0.0,0.0]
pt2 =[1.0,1.0,0.0]
?
Mark
On 2/02/2012 7:12 AM, DANIEL POSE wrote:
> Hello Mark,
>
> I understand the AutoCAD problem, but in my profession it is the most
> extended software for CAD. In my opinion it justify the efford to make
> automation tools.
> Here I post the answer from Python when I try to draw a line using
> win32com.client code in my last mail:
>
> 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\Escritorio\borrar.py", line
> 15, in <module>
> line = ms.AddLine(pt1, pt2) #This draw a line in AutoCAD
> File "<COMObject <unknown>>", line 3, in AddLine
> com_error: (-2147352567, 'Ocurri\xf3 una excepci\xf3n.', (0, None, None,
> None, 0, -2147024809), None)
>
> Thank you in advance,
> Daniel Pose.
>
> 2012/2/1 Mark Hammond <skippy.hammond at gmail.com
> <mailto:skippy.hammond at gmail.com>>
>
> Sadly not many people have access to autocad so it is hard to test.
> What errors do you get using win32com?
>
> Mark
>
>
> On 1/02/2012 5:11 AM, DANIEL POSE wrote:
>
> Hello,
>
> Recently I try to write some code to automate AutoCAD from Python. I
> have to draw lines from Python using win32com.client module, but I
> obtain error. By other hand I solved the problem using comtypes
> module.
> However, If I try to obtain block attributes information, comtypes
> doesn't work but win32com.client work properly.
>
> AutoCAD attributes working code (work for win32com.client but no for
> comtypes):
> [code]
> import win32com.client
> acad= win32com.client.Dispatch("__AutoCAD.Application")
> doc = acad.ActiveDocument
> seleccion=doc.SelectionSets.__Add('selection1')
> seleccion.SelectOnScreen()
> for objeto in seleccion:
> if objeto.ObjectName=='__AcDbBlockReference':
> bloque=objeto.GetAttributes()
> bloque[0].TagString='__newattributename' #This change
> the name
> for the first attribute in the selected block
> [/code]
>
> Draw line (work for comtypes but doesn't work for win32com.client):
> [code]
> import comtypes.client
> import array
> acad = comtypes.client.__GetActiveObject("AutoCAD.__Application")
> doc = acad.ActiveDocument
> ms = doc.ModelSpace
> pt1 = array.array('d', [0.0,0.0,0.0])
> pt2=array.array('d',[1.0,1.0,__0.0])
> line = ms.AddLine(pt1, pt2) #This draw a line in AutoCAD
> [\code]
>
> My question is: Is posible to fix the problem using win32com to draw
> autocad line in order to avoid comtypes use?
> I found on the web several coments to the problem, but no solution.
>
> Thanks for help,
> Daniel Pose.
>
>
> _________________________________________________
> python-win32 mailing list
> python-win32 at python.org <mailto:python-win32 at python.org>
> http://mail.python.org/__mailman/listinfo/python-win32
> <http://mail.python.org/mailman/listinfo/python-win32>
>
>
>
More information about the python-win32
mailing list