Skip to the content.

6. Packages

Any pure-Python or binary wheel from PyPI works in SwPy scripts: numpy, pandas, openpyxl, scipy, matplotlib … Declare what a script needs in a # r: comment (the same convention as Rhino 8):

# r: openpyxl
import openpyxl

wb = openpyxl.Workbook()
ws = wb.active
ws.append(["Dimension", "Value (mm)"])
for name, value in model.dims.items().items():
    ws.append([name, to(value, mm)])
wb.save(r"C:\temp\dimensions.xlsx")

When the script runs, missing packages are installed first (progress appears in the output panel), then the script continues. Later runs start immediately because the package is already there.

Syntax

# r: numpy
# r: pandas>=2, openpyxl
# r: requests==2.32.3

Where packages go

Packages are installed per user, into %LOCALAPPDATA%\SwPy\site-packages\py3.12 - never into a Python installation, and no admin rights are needed. This folder is on sys.path for every script and the REPL, so once installed a package can also be imported without the # r: line (keep the line anyway, so the script works on other machines).

To remove packages, delete their folders there (with SOLIDWORKS closed), or the whole folder to start over.

Notes