Python programming in autocad

Python programming in autocad

Oliver_C3D
Advocate Advocate
36,174 Views
5 Replies
Message 1 of 6

Python programming in autocad

Oliver_C3D
Advocate
Advocate
Can I write to the AutoCAD program or extension with Python?
If you can provide a tutorial or reference file in this case?
0 Likes
Accepted solutions (1)
36,175 Views
5 Replies
Replies (5)
Message 2 of 6

_gile
Consultant
Consultant

Hi,

 

You can use the pyautocad library with the AutoCAD COM API or IronPython with the AutoCAD .NET API (and also the COM API).



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 6

serag.hassouna
Advocate
Advocate

In addition to what @_gile said, there's the comtypes package.
If you understand AutoCAD's object model, you can invoke almost every method and fetch almost every value.
However, the main downside of comtypes is that you need to supply all arguments to every method you invoke, even the optional ones need to be explicitly supplied.
________
To catch the feeling of how it is "simple in theory" to connect to AutoCAD with python you can see the included code within this question of mine about an issue.
Postcommand doesn't read AutoLisp expression [Python 2.7 & AutoCAD 2016 Windows]

Message 4 of 6

rantaliran
Community Visitor
Community Visitor
hello serag.hassouna ,

I wanted to ask you for more detailed instructions, on how can I receive specific measurement from AutoCAD (maybe student addition) to a python program:)))

thank you for your help!

Ran
0 Likes
Message 5 of 6

Chuong.Ho
Advocate
Advocate

You can use project cadpythonshell, An IronPython console for Autocad and Civil 3d API, include full snoop Database to explore CAD.

https://github.com/chuongmep/CadPythonShell

 

Chuong Ho

EESignature

Message 6 of 6

joneshosting_usts
New Member
New Member
Accepted solution

Use AutoCAD python library an best python library with more features
You can do many thing like handling blocks, layers, groups, properties, ect....
https://jsweb-tech.github.io/AutoCAD/ 

> pip instal autocad
from AutoCAD import AutoCAD, APoint

cad = AutoCAD()

# Circle
circle = cad.add_circle(APoint(0, 0, 0), radius=5)

# Line
line = cad.add_line(APoint(0, 0, 0), APoint(10, 10, 0))

# Rectangle
rect = cad.add_rectangle(APoint(0, 0, 0), APoint(10, 5, 0))

# Ellipse
ellipse = cad.add_ellipse(
    center=APoint(20, 20, 0),
    major_axis=APoint(30, 0, 0),
    ratio=0.5
)