AutoCAD exposes a COM (Component Object Model) interface on Windows that lets any language — including Python — connect to a live AutoCAD session and control it programmatically. No plugins, no special AutoCAD subscription tier, no AutoLISP required. If AutoCAD is running, Python can talk to it.
This is how the Python scripts on this site work. Here's exactly how to set it up.
Install pywin32 with one command:
pip install pywin32
Open AutoCAD and load a drawing first. Then from Python:
import win32com.client
# Connect to the running AutoCAD instance
acad = win32com.client.GetActiveObject("AutoCAD.Application")
doc = acad.ActiveDocument
msp = doc.ModelSpace
print(doc.Name) # prints the current drawing filename
GetActiveObject finds AutoCAD already running on your machine — it doesn't launch a new instance. If AutoCAD isn't open you'll get an error, which is intentional. Always open AutoCAD and a drawing before running your script.
Note: This only works on Windows. The AutoCAD COM API is a Windows-only interface. Mac versions of AutoCAD don't support it.
The simplest way to control AutoCAD from Python is SendCommand — it types commands into the AutoCAD command line exactly as if you typed them yourself:
# Zoom extents
doc.SendCommand("ZOOM E\n")
# Set the current layer
doc.SendCommand("LAYER SET C-ROAD\n")
# Draw a line from 0,0 to 100,100
doc.SendCommand("LINE 0,0 100,100 \n")
The \n at the end acts as pressing Enter. This approach works for almost any AutoCAD command and is a fast way to get started.
For more control — and better reliability — you can create drawing objects directly through the COM API instead of sending text commands:
import win32com.client
import pythoncom
def make_point(x, y, z=0):
pt = win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8, [x, y, z])
return pt
acad = win32com.client.GetActiveObject("AutoCAD.Application")
msp = acad.ActiveDocument.ModelSpace
# Add a circle at 50,50 with radius 25
center = make_point(50, 50, 0)
circle = msp.AddCircle(center, 25)
# Add text
insert = make_point(10, 10, 0)
text = msp.AddText("Hello from Python", insert, 2.5)
The make_point helper is necessary because the COM API expects coordinates as a specific Windows VARIANT array type — plain Python lists won't work.
Python can also read data out of AutoCAD — coordinates, layer names, text content, block attributes. This is useful for generating reports or extracting data for other tools:
acad = win32com.client.GetActiveObject("AutoCAD.Application")
msp = acad.ActiveDocument.ModelSpace
for obj in msp:
print(obj.ObjectName, obj.Layer)
This iterates every object in model space and prints its type and layer. From here you can filter by type, read coordinates, extract text values, or write data to a CSV.
Civil 3D extends the AutoCAD COM API with its own object model. You access it like this:
acad = win32com.client.GetActiveObject("AutoCAD.Application")
# Civil 3D 2025
c3d = acad.GetInterfaceObject("AeccXUiLand.AeccApplication.13.7")
c3d_doc = c3d.ActiveDocument
# Access alignments
for alignment in c3d_doc.AlignmentsSiteless:
print(alignment.Name, alignment.Length)
The version string (13.7 for Civil 3D 2025) varies by release. You can detect it automatically or just hardcode it for your installed version.
Civil 3D note: The Civil 3D COM API is less documented than the base AutoCAD API. Some objects require specific collection access patterns. The Python scripts on this site handle this for you.
import win32com.client
acad = win32com.client.GetActiveObject("AutoCAD.Application")
doc = acad.ActiveDocument
layers = doc.Layers
prefix = "PROJ-"
for layer in layers:
if not layer.Name.startswith(prefix):
layer.Name = prefix + layer.Name
print("Done — all layers renamed")
This kind of bulk operation — touching every layer in a drawing — would take minutes manually and seconds in Python. That's the real value of COM automation: anything repetitive across many objects or many drawings becomes trivial to script.
Once you're comfortable with the basics, the natural progression is:
All of the Python scripts on this site are built on this same foundation and include the source code so you can see exactly how they work.
Tested AutoCAD and Civil 3D automation scripts with full source code included.
Browse Python Scripts →