Getting Started with Python for AutoCAD: From Zero to a Working Script in 45 Minutes
A walkthrough for solar engineers who've never written Python — install Python, set up VS Code, and run a script that reads panel coordinates from an AutoCAD CSV export. Pre-warned for every install gotcha.
Getting Started with Python for AutoCAD: From Zero to a Working Script in 45 Minutes
Every solar engineer who's written AutoLISP eventually hits the same wall: the thing they want to automate isn't a CAD drawing operation. It's a PDF from SolarEdge. Or a spreadsheet the sales team sent over. Or a web request to a permit tracker. AutoLISP has no answer for any of those. Python does.
By the end of this post you'll have Python installed, VS Code installed, and a working script that reads panel coordinates from an AutoCAD DATAEXTRACTION export. Plan for 45 minutes. Every gotcha is pre-warned.
Why Python is worth an afternoon of your time
If you've spent 20 years in AutoLISP, the case for learning a second language has to be concrete. Here it is:
- It reads file formats AutoLISP can't. PDF, Excel, JSON, CSV — every data format a solar engineer touches in a week lives in Python's standard library or one free package away. AutoLISP has zero native support for any of them.
- It runs outside AutoCAD. A Python script can sit on a server and process 200 reports overnight while you sleep. AutoLISP is locked inside an AutoCAD session.
- It has the math libraries. NumPy, scikit-learn, scipy — these are the tools that solve the routing and clustering problems behind every modern solar plugin. AutoLISP has none of them.
- It's the most-taught language in the world. Every help forum, every Stack Overflow answer, every new ML library — Python first. The volume of available examples is what makes a tool useful, not the language itself.
You don't need to abandon AutoLISP. Most engineers who pick up Python keep their LISP folder for in-AutoCAD geometry work and use Python for everything that touches files, data, or math. The two are complementary, not competitive.
Step 1: Install Python
Go to python.org/downloads. Click the big yellow "Download Python 3.12" button — the version number will drift, anything 3.10 or newer is fine.
Run the installer. Two things matter:
Check the box that says "Add python.exe to PATH" at the bottom of the first installer screen. This is the single most common install mistake. Skip it and Python installs but Windows doesn't know where to find it, and every command you try later fails with 'python' is not recognized as an internal or external command. If you already missed it, uninstall and reinstall — much easier than fixing PATH manually.
Click "Install Now" and wait. The install takes about a minute.
Verify it worked. Open PowerShell — press the Windows key, type "PowerShell," hit Enter — and run:
python --version
You should see something like Python 3.12.3. If you do, you're good. If you see 'python' is not recognized, the PATH checkbox didn't get checked. Uninstall, reinstall, check the box.
Step 2: Install VS Code
Go to code.visualstudio.com. Click "Download for Windows." Run the installer. Accept the defaults — there's nothing in the installer worth tweaking.
VS Code is what you'll write Python scripts in. It's free, made by Microsoft, and it's the default tool for Python development whether you like it or not. Other editors exist. Use VS Code anyway — every tutorial you'll find on the internet assumes you're in it.
Open VS Code after install. You'll see a welcome screen. Close it.
Step 3: Install the Python extension for VS Code
VS Code is a text editor until you tell it what kind of files you're editing. The Python extension makes it a Python editor.
Click the extensions icon on the left sidebar — looks like four squares with one detached. In the search box at the top, type Python. The first result should be Python by Microsoft, with tens of millions of downloads. Click "Install."
While you're in there, also install Python Debugger by Microsoft. Pylance is a third extension you'll want, and it usually installs automatically when you install Python — if it didn't, search for it and add it.
That's it for extensions. Don't get pulled into installing 15 of them. Start small.
Step 4: Tell VS Code which Python to use
This is the step that trips up almost every beginner. VS Code can have access to multiple Python versions on your machine, and it doesn't always pick the right one automatically.
Open the command palette: press Ctrl+Shift+P. In the search bar that appears, type Python: Select Interpreter and hit Enter. A list of installed Python versions appears. Pick the one you just installed — it should say something like Python 3.12.3 64-bit.
If no interpreters appear at all, VS Code didn't detect your install. Close VS Code, reopen it, retry. If it still doesn't show up, the PATH issue from Step 1 is back — fix that first.
Step 5: Your first script — counting panels in an AutoCAD CSV export
Here's a real workflow you'll use often. AutoCAD's DATAEXTRACTION command lets you export block attributes to a CSV. If your panels are blocks with X, Y, and PANEL_TYPE attributes, you can dump every panel in the drawing to a CSV in 30 seconds.
Set up a sample CSV. For this post, create a folder at C:\temp\ if it doesn't exist, then make a file called panels.csv in it. Open Notepad, paste this in, then save as panels.csv with "Save as type" set to "All Files" so it doesn't get saved as panels.csv.txt:
panel_id,x,y,type
P001,10.5,20.3,REC400
P002,12.0,20.3,REC400
P003,13.5,20.3,REC400
P004,10.5,22.0,REC400
P005,12.0,22.0,REC400
P006,13.5,22.0,REC400
Create a Python script. In VS Code, click File → New File. Save it as count_panels.py in C:\temp\.
Type this in (or paste it):
# count_panels.py — count panels in an AutoCAD DATAEXTRACTION CSV
import csv
csv_path = r"C:\temp\panels.csv"
panels = []
with open(csv_path, "r") as f:
reader = csv.DictReader(f)
for row in reader:
panels.append({
"id": row["panel_id"],
"x": float(row["x"]),
"y": float(row["y"]),
"type": row["type"],
})
print(f"Found {len(panels)} panels.")
xs = [p["x"] for p in panels]
ys = [p["y"] for p in panels]
print(f"Bounding box: x = {min(xs):.1f} to {max(xs):.1f}, y = {min(ys):.1f} to {max(ys):.1f}")
panel_types = set(p["type"] for p in panels)
print(f"Module types in this array: {', '.join(panel_types)}")
Run it. With count_panels.py open in VS Code, press F5 — or click the play button in the top-right corner. VS Code will ask what kind of debug configuration to use. Pick "Python File." A terminal panel will open at the bottom of the screen, and you should see:
Found 6 panels.
Bounding box: x = 10.5 to 13.5, y = 20.3 to 22.0
Module types in this array: REC400
That's a working Python program reading data from a workflow you already do.
Reading what you just wrote
Don't skip this section. The whole point of this post is that you understand what you ran, not just that it ran.
import csv — Python's standard library has a CSV reader built in. The import statement loads it. You'll write import at the top of every script.
csv_path = r"C:\temp\panels.csv" — A variable holding the file path. The r prefix means "raw string." Without it, Python would interpret \t in \temp as a tab character and break the path. Always use r"..." for Windows file paths.
with open(csv_path, "r") as f: — Opens the file for reading. The with block guarantees the file gets closed when the block exits, even if there's an error in the middle. Python enforces "remember to close your file" so you don't have to.
reader = csv.DictReader(f) — Reads the CSV in a way that gives you a dictionary per row, keyed by the column headers. Much friendlier than parsing comma-separated values yourself.
panels.append({...}) — A list of dictionaries. Each dictionary holds one panel's data. Lists and dictionaries are the two data structures you'll use 90% of the time in Python.
f"Found {len(panels)} panels." — An f-string. The f before the quote means "evaluate the expressions in curly braces." len(panels) returns the count of items in the list.
[p["x"] for p in panels] — A list comprehension. It builds a new list by pulling the "x" value out of every panel dictionary. This is one of the most-used patterns in Python and it looks weird at first. Read it as "for every p in panels, take p['x'], collect them into a list."
That's the whole script, every line. If anything is still unclear, the official Python tutorial is the best free resource on the internet.
The errors you're going to hit (and what they mean)
You will hit these. Pre-warned is half-fixed.
'python' is not recognized as an internal or external command — The PATH checkbox from Step 1 wasn't checked. Reinstall Python with the box checked.
ModuleNotFoundError: No module named 'X' — You tried to import a library that isn't installed. For built-in libraries like csv, this means you typed the name wrong. For third-party libraries (pdfplumber, numpy), you need to install them with pip install X from your terminal — covered in a follow-up post.
IndentationError: unexpected indent — Python uses indentation instead of curly braces to mark blocks of code. Accidentally put a space at the start of a line that shouldn't have one and you get this. VS Code's auto-indent will keep you out of trouble if you use Tab consistently.
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\temp\\panels.csv' — Python couldn't find the file. Either the path is wrong, or the file isn't where you think it is. Open File Explorer, navigate to C:\temp\, confirm panels.csv is there.
KeyError: 'panel_id' — Your CSV's column header is named something other than panel_id. Open the CSV in Notepad, look at the first line, match the header names exactly in your script. Python is case-sensitive — Panel_ID and panel_id are different.
Everything else — copy the entire error message, paste it into Google, add the word "python" if the result page isn't already a Python page. The first three results are usually Stack Overflow threads from someone who hit the same problem in 2014.
Where to go next
You can now read CSVs. That's already a tool — most of what solar engineers need from Python is some variation of "read this format I can't read in AutoCAD, do something with the data, write the result somewhere."
What to read next, in order:
- Python Functions, Classes, and Dataclasses for AutoLISP Programmers — translates Python syntax to LISP equivalents. Covers the OOP concepts you'll need for everything past the first script. (~25 minutes)
- Reading SolarEdge PDFs in Python: A Beginner's Guide to pdfplumber — installs your first third-party library, parses a real SolarEdge Designer report. (~30 minutes)
- Shipping Python Scripts for Solar: From VS Code to a Coworker's Desktop — how to run a script without VS Code, package it as a
.exefor teammates who don't have Python installed, and schedule unattended overnight runs. The "now what" after your first working script. (~40 minutes) - Parsing SolarEdge Designer PDFs for AutoCAD with Python and pdfplumber — the deep-dive. Production-ready PDF extraction with all four pitfalls handled. (~45 minutes)
If you want the algorithm-and-math side instead, start with What is an Auto-Stringer? The Algorithm Behind Every Solar Stringing Plugin for the conceptual primer, then Stringing Solar Panels for AutoCAD with Python for the deep-dive.
Either path, the install is done. The hard part is over.
Want to skip the language and let a plugin handle the routing, stringing, and PDF import for you? See how Branch automates all of this in AutoCAD without you writing a line of code.
- Python Functions, Classes, and Dataclasses for AutoLISP ProgrammersHow Python's def, class, and @dataclass map to AutoLISP defun and list-based data — translated for solar engineers who think in LISP and need to read modern Python code for AutoCAD work.Python Onramp~25 min read
- Reading SolarEdge PDFs in Python: A Beginner's Guide to pdfplumberHow to install pdfplumber, open a SolarEdge Designer PDF, and extract text and tables for AutoCAD import — a friendly introduction before tackling the production pitfalls.Python Onramp~30 min read
- Shipping Python Scripts for Solar: From VS Code to a Coworker's DesktopHow to run a Python solar script outside VS Code, package it for a coworker who doesn't have Python installed, and schedule it to run overnight — the three deployment paths every solar engineer needs.Python Onramp~40 min read
- Parsing SolarEdge Designer PDFs for AutoCAD with Python and pdfplumberHow to extract panel positions, string assignments, and inverter mappings from a SolarEdge Designer report PDF for AutoCAD import using Python — and the four pitfalls that will bite you.Deep Dive~45 min read
- Stringing Solar Panels for AutoCAD with Python: A 200-Line Solver You Can Run TodayA working Python solver for grouping solar panels into strings for AutoCAD drafting — what it does, what it leaves on the table, and why production tools stack four algorithms instead of one.Deep Dive~45 min read