Part Studios
This page describes the APIs Onshape provides for working with Part Studios.
📘 Notes
- This page provides sample code as curls. See the curl documentation for more information.
- All Onshape API calls must be properly authenticated by replacing the
CREDENTIALS
variable in the curls below. See the API Keys page for instructions and the Quick Start for an example. All applications submitted to the Onshape App Store must authenticate with OAuth2.- This documentation refers to Onshape IDs in the following format:
{did}, {wvmid}, {eid}, {pid}, {otherId}
. These represent document, workspace (or version or microversion), element, part, and other IDs (respectively) that are needed make the API calls. We sometimes abbreviate these variables asDWVEM
Please see API Guide: API Intro for information on what these IDs mean and how to obtain them from your documents. Never include the curly braces ({}
) in your API calls.- For Enterprise accounts, replace cad in all Onshape URLs with your company domain. https://cad.onshape.com > https://companyName .onshape.com
- For additional instruction and video content, visit the Learning Center’s Intro to the Onshape API course.
Endpoints
- createPartStudio: Create a new Part Studio tab in a document.
curl -X 'POST' \ 'https://cad.onshape.com/api/v9/partstudios/d/{did}/w/{wid}' \ -H 'Accept: application/json;charset=UTF-8; qs=0.09' \ -H 'Authorization: Basic CREDENTIALS' \ -H 'Content-Type: application/json;charset=UTF-8; qs=0.09' \ -d '{ "name": "newPartStudioTabName" }'
- getPartStudioBodyDetails: Get the body details of a Part Studio.
curl -X 'GET' \ 'https://cad.onshape.com/api/v9/partstudios/d/{did}/wvm/{wvmid}/e/{eid}/bodydetails' \ -H 'Accept: application/json;charset=UTF-8; qs=0.09' \ -H 'Authorization: Basic CREDENTIALS'
- getPartStudioNamedViews: Get the named views in a Part Studio.
curl -X 'GET' \ 'https://cad.onshape.com/api/v9/partstudios/d/{did}/e/{eid}/namedViews' \ -H 'Accept: application/json;charset=UTF-8; qs=0.09' \ -H 'Authorization: Basic CREDENTIALS'
- getPartStudioMassProperties: Get the mass properties of a Part Studio.
curl -X 'GET' \ 'https://cad.onshape.com/api/v9/partstudios/d/{did}/wvm/{wvmid}/e/{eid}/massproperties' \ -H 'Accept: application/json;charset=UTF-8; qs=0.09' \ -H 'Authorization: Basic CREDENTIALS'
- updateRollback: Move the rollback bar in the Feature list.
curl -X 'POST' \ 'https://cad.onshape.com/api/v9/partstudios/d/{did}/w/{wid}/e/{eid}/features/rollback' \ -H 'Accept: application/json;charset=UTF-8; qs=0.09' \ -H 'Authorization: Basic CREDENTIALS' -H 'Content-Type: application/json;charset=UTF-8; qs=0.09' \ -d '{ "rollbackIndex": -1 }'
- getPartStudioFeatures
curl -X 'GET' \ 'https://cad.onshape.com/api/v9/partstudios/d/{did}/{wvm}/{wvmid}/e/{eid}/features?rollbackBarIndex=-1&includeGeometryIds=true&noSketchGeometry=false' \ -H 'accept: application/json;charset=UTF-8; qs=0.09' \ -H 'Authorization: Basic CREDENTIALS'
- addPartStudioFeature
curl -X 'POST' \ 'https://cad.onshape.com/api/v9/partstudios/d/{did}/{wvm}/{wvmid}/e/{eid}/features' \ -H 'accept: application/json;charset=UTF-8; qs=0.09' \ -H 'Authorization: Basic CREDENTIALS' \ -H 'Content-Type: application/json;charset=UTF-8; qs=0.09' \ -d '{ "btType": "BTFeatureDefinitionCall-1406", "feature": { "btType": "BTMFeature-134", "featureType": "", "name": "", "parameters": [] } }'
- updatePartStudioFeature
curl -X 'POST' \ 'https://cad.onshape.com/api/v9/partstudios/d/{did}/w/{wid}/e/{eid}/features/featureid/{fid}' \ -H 'Accept: application/json;charset=UTF-8; qs=0.09' \ -H 'Authorization: Basic CREDENTIALS' \ -H 'Content-Type: application/json;charset=UTF-8; qs=0.09' \ -d '{ "btType": "BTFeatureDefinitionCall-1406", "feature": { "btType": "BTMFeature-134", "featureId": "{fid}", "parameters": [] } }'
- updateFeatures
curl -X 'POST' \ 'https://cad.onshape.com/api/v9/partstudios/d/{did}/w/{wid}/e/{eid}/features/updates' \ -H 'Accept: application/json;charset=UTF-8; qs=0.09' \ -H 'Authorization: Basic CREDENTIALS' \ -H 'Content-Type: application/json;charset=UTF-8; qs=0.09' \ -d '{ "btType": "BTUpdateFeaturesCall-1748", "features": [ { "btType": "BTMFeature-134", "featureId": "{fid1}", "parameters": [] }, { "btType": "BTMFeature-134", "featureId": "{fid2}", "parameters": [] } ] }'
- deletePartStudioFeature
curl -X 'DELETE' \ 'https://cad.onshape.com/api/v9/partstudios/d/{did}/{wvm}/{wvmid}/e/{eid}/features/featureid/{fid}' \ -H 'accept: application/json;charset=UTF-8; qs=0.09' \ -H 'Authorization: Basic CREDENTIALS'
Sample Workflows
Create a Part Studio
- Open an Onshape document or create a new one.
- Call the createPartStudio endpoint. Specify a
name
for the new tab in the request body; in this example, we’ll call itnewPartStudio1
.curl -X 'POST' \ 'https://cad.onshape.com/api/v9/partstudios/d/{did}/w/{wid}' \ -H 'Accept: application/json;charset=UTF-8; qs=0.09' \ -H 'Authorization: Basic CREDENTIALS' \ -H 'Content-Type: application/json;charset=UTF-8; qs=0.09' \ -d '{ "name": "newPartStudio1" }'
- Return to your document and observe that the new assembly tab has been added.
Get the list of features in a Part Studio
One of the best ways to familiarize yourself with the Onshape Feature APIs is to view the API details for existing features in a Part Studio. In this example, we’ll add three features to a Part Studio, and then call the getPartStudioFeatures API on the Part Studio. We’ll then be able to view the structure of the way features are represented in the API.
- Create a new document or open an existing one.
- Create a new sketch in the document, and draw a long rectangle.
- Extrude the rectangle.
- Add a fillet to one edge of the part.
- Call the getPartStudioFeatures API. Replace the URL parameters with the values from your document, and replace
CREDENTIALS
with your authorization credentials.curl -X 'GET \ 'https://cad.onshape.com/api/v9/partstudios/d/{did}/{wvm}/{wvmid}/e/{eid}/features?rollbackBarIndex=-1&includeGeometryIds=true&noSketchGeometry=false' \ -H 'Authorization: Basic CREDENTIALS' \ -H 'Accept: application/json;charset=UTF-8; qs=0.09'
- Review the JSON returned in the response body. A lot of information is returned, but it will look something like the truncated snippet below. Notice that there are objects returned for each feature in the Part Studio– the sketch, the extrude, the fillet, and the chamfer. Each default plane and the origin in the Part Studio also appear in the
defaultFeatures
object. The Standard Geometry library is listed as an import, and the response also includes the state of each feature. :{ "btType": "BTFeatureListResponse-2457", "isComplete": true, "serializationVersion": "1.2.4", "rollbackIndex": 4, "features": [ { "btType": "BTMSketch-151", "entities": [...], "constraints": [...], "name": "Sketch 1", "suppressed": false, "parameters": [...], "featureId": "{fid1}", "featureType": "newSketch", "subFeatures": [...], "returnAfterSubfeatures": false }, { "btType": "BTMFeature-134", "name": "Extrude 1", "suppressed": false, "parameters": [...] "featureId": "{fid2}", "featureType": "extrude", "subFeatures": [], "returnAfterSubfeatures": false }, { "btType": "BTMFeature-134", "name": "Fillet 1", "suppressed": false, "parameters": [...], "featureId": "{fid3}", "featureType": "fillet", "subFeatures": [...], "returnAfterSubfeatures": false }, { "btType": "BTMFeature-134", "name": "Chamfer 1", "suppressed": false, "parameters": [...], "featureId": "{fid4}", } ], "featureStates": { "{fid1}": { "btType": "BTFeatureState-1688", "featureStatus": "OK", "inactive": false }, ... }, "defaultFeatures": [ { "btType": "BTMFeature-134", "name": "Origin", }, { "btType": "BTMFeature-134", "name": "Top", }, { "btType": "BTMFeature-134", "name": "Front", }, { "btType": "BTMFeature-134", "name": "Right", } ], "imports": [ { "btType": "BTMImport-136", "path": "onshape/std/geometry.fs", "version": "2232.0" } ], "libraryVersion": 2232 }
Create a cube feature
In this example we will create a cube using the cube
feature. The feature accepts a single parameter (the length of a side) and creates a cube with a corner at the origin and aligned with the three default planes.
- Create a new document or open an existing one. We’ll create the cube feature in this document.
- Begin to create the addPartStudioFeature call. Replace the URL parameters with the values from your document, and replace
CREDENTIALS
with your authorization credentials. This is a call to the same endpoint as in the previous example, but is aPOST
instead of aGET
.curl -X 'POST \ 'https://cad.onshape.com/api/v9/partstudios/d/{did}/{wvm}/{wvmid}/e/{eid}/features' \ -H 'Authorization: Basic CREDENTIALS' \ -H 'Accept: application/json;charset=UTF-8; qs=0.09'\ -H 'Content-Type: application/json;charset=UTF-8; qs=0.09' \ -d '{ <JSON of feature data> }'
- Add the following as the JSON body.
- Note the
btType
defines this as a Feature. - We’ve named the feature
cube
and inserted an instance of the feature namedCube 1
into the Part Studio. - The
cube
feature has one parameter– the cubesideLength
in inches, which is set to 1 by default.
{ "btType": "BTFeatureDefinitionCall-1406", "feature": { "btType": "BTMFeature-134", "featureType": "cube", "name": "Cube 1", "parameters": [ { "btType": "BTMParameterQuantity-147", "isInteger": false, "expression": "1 in", "parameterId": "sideLength" } ], "returnAfterSubfeatures": false, "suppressed": false } }
- Note the
- Confirm your call matches the following, and then make the call:
curl -X 'POST \ 'https://cad.onshape.com/api/v9/partstudios/d/{did}/{wvm}/{wvmid}/e/{eid}/features' \ -H 'Authorization: Basic CREDENTIALS' \ -H 'Accept: application/json;charset=UTF-8; qs=0.09'\ -H 'Content-Type: application/json;charset=UTF-8; qs=0.09' \ -d '{ "btType": "BTFeatureDefinitionCall-1406", "feature": { "btType": "BTMFeature-134", "featureType": "cube", "name": "Cube 1", "parameters": [ { "btType": "BTMParameterQuantity-147", "isInteger": false, "expression": "1 in", "parameterId": "sideLength" } ], "returnAfterSubfeatures": false, "suppressed": false } }'
- Return to your console to review the endpoint response. The output returns:
- The feature definition that we provided as input with
nodeId
s and afeatureId
. Make a note of thefeatureId
; we’ll use it in the next example. - Information that the feature executed correctly
- The serialization version and microversion of the document that resulted from the feature addition
{ "btType": "BTFeatureDefinitionResponse-1617", "featureState": { "btType": "BTFeatureState-1688", "featureStatus": "OK", "inactive": false }, "feature": { "btType": "BTMFeature-134", "name": "Cube 1", "suppressed": false, "parameters": [ { "btType": "BTMParameterQuantity-147", "value": 0, "units": "", "isInteger": false, "expression": "1 in", "nodeId": "{nid1}", "parameterId": "sideLength" } ], "featureId": "{fid}", "nodeId": "{nid2}", "featureType": "cube", "returnAfterSubfeatures": false, "subFeatures": [], "namespace": "" }, "serializationVersion": "1.2.4", "sourceMicroversion": "{mid}", "microversionSkew": false, "rejectMicroversionSkew": false, "libraryVersion": 0 }
- The feature definition that we provided as input with
- Open your document and confirm that the cube has been inserted into the Part Studio.
- Double-click
Cube 1
in the Feature List to open the Cube 1 dialog. Change the sideLength to 3 and click the checkbox. Note that the size of the cube changes automatically.
Update a feature
In this example we’ll update our cube feature.
- Open the document in which you created the cube feature in this example. You will need the following from this document:
- Document ID
- Workspace ID
- Element ID (for the element that contains the cube feature)
- Feature ID (ID of the cube feature, returned in the API response in the previous example)
- If you need to get this
featureId
again, you can call the getPartStudioFeatures endpoint on the document.
- If you need to get this
- Begin to create the updatePartStudioFeature call. Replace the URL parameters with the values from your document, and replace
CREDENTIALS
with your authorization credentials.curl -X 'POST' \ 'https://cad.onshape.com/api/v9/partstudios/d/{did}/w/{wid}/e/{eid}/features/featureid/{fid}' \ -H 'Accept: application/json;charset=UTF-8; qs=0.09' \ -H 'Authorization: Basic CREDENTIALS' \ -H 'Content-Type: application/json;charset=UTF-8; qs=0.09' \ -d '{ <JSON of feature data> }'
- Add the following as the JSON body.
- Note the
btType
defines this as a Feature. - We specify the
featureId
again in the request body. This must match thefeatureId
sent in the URL exactly. - We must also specify the feature’s
featureType
andname
in this call; if we don’t send those fields, the call will attempt to change these values to empty strings, resulting in errors. - The
cube
feature has one parameter– the cubesideLength
in inches, which we will update to 2 inches:
{ "btType": "BTFeatureDefinitionCall-1406", "feature": { "featureId": "{fid}", "featureType": "cube", "name": "Cube 1", "parameters": [ { "btType": "BTMParameterQuantity-147", "isInteger": false, "expression": "2 in", "parameterId": "sideLength" } ] } }
- Note the
- Confirm your call matches the following, and then make the call:
curl -X 'POST' \ 'https://cad.onshape.com/api/v9/partstudios/d/{did}/w/{wid}/e/{eid}/features/featureid/{fid}' \ -H 'Accept: application/json;charset=UTF-8; qs=0.09' \ -H 'Authorization: Basic CREDENTIALS' \ -H 'Content-Type: application/json;charset=UTF-8; qs=0.09' \ -d '{ "btType": "BTFeatureDefinitionCall-1406", "feature": { "featureId": "{fid}", "featureType": "cube", "name": "Cube 1", "parameters": [ { "btType": "BTMParameterQuantity-147", "isInteger": false, "expression": "2 in", "parameterId": "sideLength" } ] } }'
- Return to your console to review the endpoint response. The output returns:
- The updated feature definition
- Information that the feature executed correctly
- The serialization version and microversion of the document that resulted from the feature update
{ "btType": "BTFeatureDefinitionResponse-1617", "featureState": { "btType": "BTFeatureState-1688", "featureStatus": "OK", "inactive": false }, "feature": { "btType": "BTMFeature-134", "name": "Cube 1", "suppressed": false, "parameters": [ { "btType": "BTMParameterQuantity-147", "value": 0, "units": "", "isInteger": false, "expression": "2 in", "nodeId": "{nid1}", "parameterId": "sideLength" } ], "featureId": "{fid}", "nodeId": "{nid2}, "featureType": "cube", "returnAfterSubfeatures": false, "subFeatures": [], "namespace": "" }, "serializationVersion": "1.2.4", "sourceMicroversion": "{mid}", "microversionSkew": false, "rejectMicroversionSkew": false, "libraryVersion": 0 }
- Open your document and confirm that the cube has a side length of 2 inches.
Delete a feature
- Create a new document and add a cube feature to it. See Create a cube feature for instructions. Make a note of the following:
- Document ID
- Workspace ID
- Element ID (for the element containing the cube feature)
- Call the getPartStudioFeatures endpoint on the document to get the
featureId
of the cube feature. See Get the Feature list for instructions. - Create and execute the deletePartStudioFeature call. Replace the URL parameters with the values from your document, and replace
CREDENTIALS
with your authorization credentials.curl -X 'DELETE' \ 'https://cad.onshape.com/api/v9/partstudios/d/{did}/w/{wid}/e/{eid}/features/featureid/{fid}' \ -H 'Accept: application/json;charset=UTF-8; qs=0.09' \ -H 'Authorization: Basic CREDENTIALS'
- Confirm that the cube feature has been removed from your document.
Get the body details of a Part Studio
- Open this public document and make a note of the IDs in the URL.
- Call the getPartStudioBodyDetails endpoint.
curl -X 'GET' \ 'https://cad.onshape.com/api/v9/partstudios/d/e60c4803eaf2ac8be492c18e/w/d2558da712764516cc9fec62/e/958bceb5a2511b572dbbe851/bodydetails' \ -H 'Accept: application/json;charset=UTF-8; qs=0.09' \ -H 'Authorization: Basic CREDENTIALS'
- Review the body details of the Part Studio in the response.
Get the mass properties of a Part Studio
- Open this public document and make a note of the IDs in the URL.
- Call the getPartStudioMassProperties endpoint.
curl -X 'GET' \ 'https://cad.onshape.com/api/v9/partstudios/d/e60c4803eaf2ac8be492c18e/w/b4d1281b4c9b7828ae48963b/e/cdc8fd6b9d87a89bd6c632b9/massproperties' \ -H 'Accept: application/json;charset=UTF-8; qs=0.09' \ -H 'Authorization: Basic CREDENTIALS'
- Review the mass details in the response. You can see that three values are returned for the mass– the mass, and both the upper and lowerance tolerance limits. You can also view volume, centroid, peripherary, and other details in the response.
{ "microversionId": "228dec253307cc94e9f746b1", "bodies": { "-all-": { "mass": [ 0.02582875039789768, 0.025813408952295558, 0.025844091843499797 ], "volume": [ 0.0000032902866748914245, 0.000003288111159757221, 0.000003292462190025627 ], "periphery": [ 0.0025911116902471044, 0.002590489537448614, 0.002591733843045594 ], "centroid": [ 6.227949492879002e-9, 0.01796696283822726, -4.978549374055619e-9, -0.0000028838934381085144, 0.017934259287073262, -0.0000020997040077128094, 0.00000289635673978722, 0.017999704072996676, 0.0000020897409913392822 ], "inertia": [ 0.000012786829765475387, 2.590953253572762e-12, -5.855599674990544e-13, 2.590953253572762e-12, 6.515947644744094e-7, 2.843608507264417e-12, -5.855599674990544e-13, 2.843608507264417e-12, 0.000013221652288414688, 0.000012781057998408856, -9.304875897356356e-10, -6.572144049387908e-11, -9.304875897356356e-10, 6.464712394032286e-7, -5.721285557988916e-10, -6.572144049387908e-11, -5.721285557988916e-10, 0.000013215719933162684, 0.00001279259621446907, 9.356661065116923e-10, 6.454997003897911e-11, 9.356661065116923e-10, 6.567182886601889e-7, 5.778184825244676e-10, 6.454997003897911e-11, 5.778184825244676e-10, 0.000013227579325341992 ], "hasMass": true, "massMissingCount": 0, "principalInertia": [ 6.515947644732128e-7, 0.000012786829765475152, 0.000013221652288416117 ], "principalAxes": [ { "x": 2.1350665115465576e-7, "y": -0.9999999999999516, "z": 2.2622079877752135e-7 }, { "x": -0.9999999999990705, "y": -2.1350695579762348e-7, "z": -0.0000013466629014772562 }, { "x": 0.0000013466629497769047, "y": -2.2622051129572718e-7, "z": -0.9999999999990675 } ] } } }
Move the rollback bar
- Make a copy of this public document and make a note of the IDs in the URL of the new document.
- Call the updateRollback endpoint.
curl -X 'POST' \ 'https://cad.onshape.com/api/v9/partstudios/d/{did}/w/{wid}/e/{eid}/features/rollback' \ -H 'Accept: application/json;charset=UTF-8; qs=0.09' \ -H 'Authorization: Basic CREDENTIALS' -H 'Content-Type: application/json;charset=UTF-8; qs=0.09' \ -d '{ "rollbackIndex": 2 }'
- Go back to your document and observe that the rollback bar has been moved up in the Feature list.
- Call the updateRollback endpoint again, but this time set the rollback bar to
-1
to move it back to the bottom of the list.curl -X 'POST' \ 'https://cad.onshape.com/api/v9/partstudios/d/{did}/w/{wid}/e/{eid}/features/rollback' \ -H 'Accept: application/json;charset=UTF-8; qs=0.09' \ -H 'Authorization: Basic CREDENTIALS' -H 'Content-Type: application/json;charset=UTF-8; qs=0.09' \ -d '{ "rollbackIndex": -1 }'
- Go back to your document and see that the rollback bar is back at the bottom of the Feature list:
Update a tab name
In this example we will update an element’s tab name by getting the current metadata for the element, and then posting an update to that metadata. Remember that in Onshape, an element is typically represented as a tab in the Onshape UI.
Get your document information:
Make a copy of this public document. Make a note of the new document’s document ID, workspace ID, and element ID. Note the tab name of the element is “NEW_PART”.
Get the metadata of the element:
We’ll call the getWMVEMetadata endpoint to get the current metadata JSON for the element. Don’t forget to replace the URL parameters with the IDs from your copied document, and replace
CREDENTIALS
with your authorization credentials.curl -X 'GET' \ 'https://cad.onshape.com/api/v6/metadata/d/{did}/w/{wid}/e/{eid}' \ -H 'accept: application/json;charset=UTF-8; qs=0.09' \ -H 'Authorization: Basic CREDENTIALS' \ -H 'Content-Type: application/json;charset=UTF-8; qs=0.09'
Locate the property to update in the response:
The call returns a response body in JSON format. Scroll to the
Name
properties block of the JSON response, and notice that thevalue
field matches our current tab name, “NEW_PART”.{ "jsonType": "metadata-element", "elementType": 0, "mimeType": "onshape/partstudio", "elementId": "{eid}", "properties": [ { "name": "Name", "value": "NEW_PART", "validator": {}, "required": true, "editable": true, "propertyId": "{propertyId}", }, ... ], ... }
Find the metadata’s property ID:
Copy the Name block’s
propertyId
in the response. We’ll need this ID to update the metadata.Set up the updateWVEMetadata call:
curl -X 'POST' \ 'https://cad.onshape.com/api/v6/metadata/d/{did}/w/{wid}/e/{eid}' \ -H 'accept: application/json;charset=UTF-8; qs=0.09' \ -H 'Authorization: Basic CREDENTIALS' \ -H 'Content-Type: application/json;charset=UTF-8; qs=0.09' \
Add the request JSON to the call:
Note that we need to include the
propertyId
and the value to update.-d '{ "properties": [ { "value": "", "propertyId": "{propertyId}" } ] }'
Add the new property information:
In the request JSON, replace
{propertyId}
with the property ID you found in Step 4, then change the emptyvalue
string to"PISTON"
:-d '{ "properties": [ { "value": "PISTON", "propertyId": "{propertyId}" } ] }'
POST the new metadata:
Don’t forget to replace the URL parameters and
CREDENTIALS
with your information.curl -X 'POST' \ 'https://cad.onshape.com/api/v6/metadata/d/{did}/w/{wid}/e/{eid}' \ -H 'accept: application/json;charset=UTF-8; qs=0.09' \ -H 'Authorization: Basic CREDENTIALS' \ -H 'Content-Type: application/json;charset=UTF-8; qs=0.09' \ -d '{ "properties": [ { "value": "PISTON", "propertyId": "{propertyId}" } ] }'
Confirm your changes:
Open your document and confirm that the tab name is now
PISTON
.
Work with features
See the Features API Guide for additional tutorials for working with features.