Software · completed
Onshape Toolkit
I built this while working on actuator and mechanism design, where manually updating link lengths and gear parameters across dozens of configurations wasn’t sustainable. The workflow I wanted was simple: keep the design variables in a text file (or generate them from an optimizer), run one command, and watch the CAD model update.
Why a separate library
I also contributed to the Neurobionics Lab’s onshape-robotics-toolkit, a full library for working with Onshape robot models. It does a lot more than this, and it’s a much bigger dependency. Many people just want to change a few variables in a Variable Studio from Python. Onshape Toolkit is that one feature on its own: a few small modules, no robotics stack, and easy to read in one sitting.
What it does
- Authenticates with the Onshape REST API (v9) using HMAC-SHA256 signed requests.
- Reads a Variable Studio’s variables: names, types and expressions.
- Parses a plain text file of variables and pushes them to the CAD model in one call.
- Handles types automatically: angles become
ANGLE, integer counts such as gear tooth numbers becomeNUMBER, and everything else becomesLENGTH, withmmadded when no unit is given.
A variable file is just name–value pairs:
"Ns"= 24
"Np"= 42
"Nr"= 108
"module"= 0.6
"num_planet"= 3
"pressure_angle"= 20.0deg
Pushing it to a model:
from onshape_toolkit.client import Client, Document
from onshape_toolkit.variables import parse_variable_file
client = Client(env=".env")
doc = Document.from_url("https://cad.onshape.com/documents/<did>/w/<wid>/e/<eid>")
variables = parse_variable_file("data/sspg_equations.txt")
client.set_variables(doc.did, doc.wid, doc.eid, variables)
This turns a parametric sweep or an optimization loop into a script instead of an afternoon of clicking.