elmasea
1st Jun 2010, 08:03 pm
Hi I am seeking “partners” on studing python for autocad
I am a mechanical designer, an (italian) autocad user.
Until a few years ago I programmed in lisp, but then I have used VBA.
Now I'm learning python, as you know, powerful and easy to use
Of course I use win32com class
So I did the first routine about Python/Autocad that I try to explain briefly:
1) Reading all the characteristics of a selected entity:
acad = win32com.client.Dispatch("AutoCAD.Application")
doc = acad.ActiveDocument # Document object
ms = doc.ModelSpace # Modelspace "collection"
returnObj = doc.Utility.GetEntity() # "Select an object")
then I can display the properties of the selected entity
eg for a polyline:
returnObj[0].Coordinates ...
or other
Layer, Length, Linetype, LinetypeScale, Lineweight
But this is true only for a selected entity (GetEntity method),
2) Reading all the characteristics of a indexed entity:
When I get an entity at a given index
ms = doc.ModelSpace
i = 5 # index of the entity in the drawing (Modelspace)
entObj = ms.Item(i)
I can display only few properties
for example, always for a polyline :
entObj.Layer
entObj.ObjectName
but for other properties python tells me the object has no attribute 'for example Length, Coordinates,
Instead VBA does that
who wants to help me?
who wants to partecipate?
elmasea
I am a mechanical designer, an (italian) autocad user.
Until a few years ago I programmed in lisp, but then I have used VBA.
Now I'm learning python, as you know, powerful and easy to use
Of course I use win32com class
So I did the first routine about Python/Autocad that I try to explain briefly:
1) Reading all the characteristics of a selected entity:
acad = win32com.client.Dispatch("AutoCAD.Application")
doc = acad.ActiveDocument # Document object
ms = doc.ModelSpace # Modelspace "collection"
returnObj = doc.Utility.GetEntity() # "Select an object")
then I can display the properties of the selected entity
eg for a polyline:
returnObj[0].Coordinates ...
or other
Layer, Length, Linetype, LinetypeScale, Lineweight
But this is true only for a selected entity (GetEntity method),
2) Reading all the characteristics of a indexed entity:
When I get an entity at a given index
ms = doc.ModelSpace
i = 5 # index of the entity in the drawing (Modelspace)
entObj = ms.Item(i)
I can display only few properties
for example, always for a polyline :
entObj.Layer
entObj.ObjectName
but for other properties python tells me the object has no attribute 'for example Length, Coordinates,
Instead VBA does that
who wants to help me?
who wants to partecipate?
elmasea