Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- Be respectful, on topic and if you see a problem, Flag it.
If you would like to contact our Community Manager personally, feel free to send a private message or an email.
Creating a new Feature via API JSON Format (NodeJS)
"moreInfoUrl" : "",<br> "message" : "Error in input",<br> "status" : 400,<br> "code" : 9999
A feature can be added to the feature list by calling the add feature API. The API accepts as input a JSON structure containing the fields:
feature - A single feature definition, in the same format that is output by the get feature list API, except that there is no need to provide feature ids, node ids, or typeNames.
sourceMicroversion - The microversion of the document that is assumed. Any geometry ids included in the feature are interpreted in the context of this microversion.
rejectMicroversionSkew (optional) - If set to true, the call will refuse to make the addition if the current microversion for the document does not match the source Microversion. Otherwise, a best-effort attempt is made to re-interpret the feature addition in the context of a newer document microversion.
- I crossed out the parameters, that I think could be left out - is that correct?
- Can I leave out even more?
- What does the "type" parameter mean, is there a reference to get the different type-IDs?
- Do I (in this case) have to send all the parameters (like for example the angleValues) eventhough I don't need them?
<div>{ type: 134,<br> typeName: 'BTMFeature',<br> message:<br> { featureType: 'assignVariable',<br> featureId: 'FBDKLiWSFhxivCS_4',<br> name: '###name = #value',<br> parameters:<br> [ { type: 145,<br> <strike>typeName: 'BTMParameterEnum',</strike><br> message:<br> { enumName: 'VariableType',<br> value: 'LENGTH',<br> namespace: '',<br> parameterId: 'variableType',<br> hasUserCode: false,<br> <strike>nodeId: '1RAiTT9k/YZWmNgz'</strike> } },<br> { type: 149,<br> <strike>typeName: 'BTMParameterString',</strike><br> message:<br> { value: 'height',<br> parameterId: 'name',<br> hasUserCode: false,<br> <strike>nodeId: '2mqEuNkuTwd4X24B'</strike> } },<br> { type: 147,<br> <strike> typeName: 'BTMParameterQuantity'</strike>,<br> message:<br> { units: '',<br> value: 0,<br> expression: '20 mm',<br> isInteger: false,<br> parameterId: 'lengthValue',<br> hasUserCode: false,<br> <strike>nodeId: 'oqr4JEGmAvo46VbB' </strike>} },<br> { type: 147,<br> <strike>typeName: 'BTMParameterQuantity',</strike><br> message:<br> { units: '',<br> value: 0,<br> expression: '0 deg',<br> isInteger: false,<br> parameterId: 'angleValue',<br> hasUserCode: false,<br> <strike>nodeId: 'GimpgbFzb/8Z7IaC'</strike> } },<br> { type: 147,<br> <strike>typeName: 'BTMParameterQuantity',</strike><br> message:<br> { units: '',<br> value: 0,<br> expression: '0',<br> isInteger: false,<br> parameterId: 'numberValue',<br> hasUserCode: false,<br> <strike>nodeId: '5mxSEl+E6b6DnP4/'</strike> } },<br> { type: 147,<br> <strike>typeName: 'BTMParameterQuantity',</strike><br> message:<br> { units: '',<br> value: 0,<br> expression: '0',<br> isInteger: false,<br> parameterId: 'anyValue',<br> hasUserCode: false,<br> nodeId: 'gHBfTGWBv2ekydiC' } },<br> { type: 147,<br> <strike>typeName: 'BTMParameterQuantity'</strike>,<br> message:<br> { units: '',<br> value: 0,<br> expression: '20 mm',<br> isInteger: false,<br> parameterId: 'value',<br> hasUserCode: false,<br> <strike>nodeId: 'MIPxQRFxB9slK+pV'</strike> } } ],<br> suppressed: false,<br> namespace: '',<br> subFeatures: [],<br> returnAfterSubfeatures: false,<br> suppressionState: { type: 0 },<br> hasUserCode: false,<br> <strike>nodeId: 'MhQQaUQzEjzS4GyOn'</strike> } }<br></div><div><br></div><div></div>
<div><br></div><br><div><div>const addFeature = (documentId, wvm, wvmId, elementId, feature,conf, cb) => {</div><div> var opts = {</div><div> d: documentId,</div><div> e: elementId,</div><div> resource: 'partstudios',</div><div> subresource: 'features',</div><div> feature,</div><div> sourceMicroversion: conf.sourceMicroversion,</div><div> serializationVersion: conf.serializationVersion</div><div> };</div><div> opts[wvm] = wvmId;</div><div> onshape.post(opts, cb);</div><div>}</div></div>
Comments
Type: Length
name: xyz
value: 1.01*in
type corresponds to the parameter type (which is in plain text typeName).
We've been working on improved ways of documenting (and generating) features through the API. But currently I think the best way to get it is via a GET on the featurelist to get a representative feature and fill in the blanks.