| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
SwPy embeds real CPython inside SOLIDWORKS. Write and run Python against the live SOLIDWORKS API from a task-pane IDE, use a Pythonic layer for everyday jobs, install any pip package, and drive SOLIDWORKS from Jupyter or other applications.
# r: openpyxl # pip packages on demand
with model.batch(): # many edits, one rebuild
model.dims["D1@Boss-Extrude1"] = 25 * mm # SI units, no casts
model.globals["Width"] = 120 * mm
model.faces.planar().normal(Z).largest().select() # geometry queries
print(model.mass["mass"], "kg")In-process Python
Task-pane IDE
Pythonic API (swpy.model)
Full SOLIDWORKS API
Events
Tools for your team
Packages and automation
| OS | Windows 10/11 x64 |
| SOLIDWORKS | 2020 or newer (developed and tested on 2020 SP1) |
| Python | none for users (bundled 3.12); Python 3.10+ with pywin32 for the remote client |
| Rights | standard user; admin only for optional machine-wide auto-load |
Download SwPy-x.y.z.zip from the latest release and unzip it to a permanent folder (e.g. %LOCALAPPDATA%\Programs\SwPy), or build from source.
In that folder, register SwPy for your Windows user and create the SOLIDWORKS + SwPy shortcut:
powershell -ExecutionPolicy Bypass -File tools\install.ps1Start SOLIDWORKS with the SOLIDWORKS + SwPy shortcut and open the SwPy - Python tab of the task pane.
Options: -Machine also registers SwPy machine-wide, so SOLIDWORKS loads it at every start (needs admin). -Uninstall removes everything.
Open a part, type into the editor and press F5:
for f in model.features():
print(f.GetTypeName2().ljust(16), f.Name)
print("volume:", round(to(model.mass["volume"], mm**3)), "mm^3")From Jupyter or another Python (pip install -e .[client] from this repository):
import swpy.client as swc
sw = swc.connect()
sw.eval("model.mass['mass']") # -> 0.12The user guide (also as a website: https://muerus.github.io/SolidWorks-Python/) covers everything:
| Getting started | Install, first script, where files live |
| The editor | IntelliSense, shortcuts, tabs, find/replace |
| Scripting basics | Predefined names, sessions, output, units |
| The model API | Dimensions, globals, batch, mass, face/edge queries |
| SOLIDWORKS API from Python | Auto-typing, casts, enums, arrays, out-parameters, porting VBA |
| Packages | # r: requirements |
| Remote control | Jupyter, scripts, Excel, C# |
| Recipes | Parts from scratch, studies, exports, properties, assemblies |
| Troubleshooting | Logs and common errors |
| Events | Handlers for rebuilds, saves, selections, document switches |
| Script buttons and UI | Script folder, buttons, startup scripts, progress (Esc cancels), dialogs |
| Building models | Sketches, features, assemblies and mates, drawings, export |
| API reference | Every public class and function |
Every runnable example in the guide is executed against SOLIDWORKS by the test suite.
SOLIDWORKS (SLDWORKS.exe, .NET Framework 4.8)
└─ SwPy.AddIn (C#) ── task pane IDE (WinForms + Scintilla)
│ └─ COM entry point Execute(session, code) ◄── swpy.client / Excel / C#
└─ pythonnet ──► CPython 3.12 (bundled)
├─ swpy._host sessions, output, errors, # r: packages
├─ swpy._editor completion, signatures, hover, syntax check
├─ swpy.com auto-typed COM proxies
└─ swpy.model Pythonic layer (units, dims, globals, queries)
├── src/ │ ├── SwPy.AddIn/ C# add-in: COM registration, Python host, task-pane IDE (Ui/) │ └── SwPy.Launcher/ starts SOLIDWORKS and loads the add-in (per-user installs) ├── python/swpy/ the Python package (runs inside SOLIDWORKS; client.py runs anywhere) ├── tests/ live pytest suite (drives a real SOLIDWORKS) ├── tools/ install/register scripts, runtime fetcher, interop generator ├── docs/ │ └── guide/ user guide and API reference ├── pyproject.toml package metadata (editable install for the client / dev tools) ├── CHANGELOG.md ├── CONTRIBUTING.md └── LICENSE
py -3.12 -m venv .venv; .venv\Scripts\pip install -e .[dev]
powershell tools\fetch_python.ps1 # bundle the embeddable runtime (optional for dev)
dotnet build src\SwPy.AddIn -c Debug # SOLIDWORKS must be closed (DLL lock)
dotnet build src\SwPy.Launcher -c Debug
powershell tools\register.ps1 # per-user COM registration of the Debug build
.venv\Scripts\python -m pytest tests -q # starts SOLIDWORKS, loads the add-in, runs the suiteRelease package: powershell tools\package.ps1 builds dist\SwPy-<version>.zip. See CONTRIBUTING.md for the test layout, the dev loop (reloading Python without restarting SOLIDWORKS), conventions and release builds. Logs: %LOCALAPPDATA%\SwPy\logs\swpy.log.
SwPy runs scripts with your Windows permissions inside SOLIDWORKS - treat scripts like macros and only run code you trust. See SECURITY.md for the trust model and how to report a vulnerability.
See CHANGELOG.md.
MIT © 2026 muerus. SOLIDWORKS is a registered trademark of Dassault Systèmes SolidWorks Corporation. This project is not affiliated with or endorsed by Dassault Systèmes.
| Back | FazBrowse Home | New Git URL |