Set a Part Studio variable
onshape_set_variableCreates or updates a named variable in an Onshape document so feature dimensions can reference it by name, keeping a shared value in one place.
Instructions
Create or update a variable. Feature tools can then reference it by name (depth_variable, radius_variable, ...) so a dimension lives in one place. Uses the variable table where the account supports it and falls back to an assignVariable feature otherwise; result.route says which was used.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"doc": "<doc>",
"ws": "<ws>",
"elem": "<elem>",
"name": "<name>",
"expression": "<expression>"
},
"name": "onshape_set_variable"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ws | Yes | Workspace id — the <ws> segment of the document URL. | |
| doc | Yes | Document id — the <doc> in cad.onshape.com/documents/<doc>/w/<ws>/e/<elem>. | |
| elem | Yes | Element id (tab) — the <elem> segment of the document URL. | |
| name | Yes | Variable name, without the leading #. | |
| type | No | Variable type; inferred from the expression's units when omitted. | |
| expression | Yes | Value expression with units, e.g. "0.25 in" or "2 * #wall". | |
| description | No | What the variable means. |