Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. 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.

API for beginners

lajos_szabó013lajos_szabó013 Member Posts: 10 EDU
Hi, 

I really need some help, since I am struggling hard with Onshape API.
Using VSCode Python I managed to request successfully for new 'Document' and 'Part Studio'. Now it would be nice to have some features inside a 'Part Studio' but I have not found any way to make it work.

I read "Feature List API" (https://onshape-public.github.io/docs/api-adv/featureaccess/) and browsed Glassworks (https://cad.onshape.com/glassworks/explorer/)

From where can I get the right parameters for a /partstudios/.../features API call?

{
  "btType": "string",
  "feature": {
    "featureId": "string",
    "featureType": "string",
    "importMicroversion": "string",
    "name": "string",
    "namespace": "string",
    "nodeId": "string",
    "parameters": [
      {
        "importMicroversion": "string",
        "nodeId": "string",
        "parameterId": "string"
      }
    ],
    "returnAfterSubfeatures": true,
    "subFeatures": [
      "string"
    ],
    "suppressed": true,
    "suppressionConfigured": true,
    "variableStudioReference": true
  },
  "libraryVersion": 0,
  "microversionSkew": true,
  "rejectMicroversionSkew": true,
  "serializationVersion": "string",
  "sourceMicroversion": "string"
}
 
Can anyone send me a link for a detailed documentation about the paramteres, like featureTypes, btTypes with some examples?

 Or can anyone help me how to make a cylinder?

Thanks in advance

Lajos

Answers

  • Paul_J_PremakumarPaul_J_Premakumar Member, Onshape Employees Posts: 223
    Hi Lajos,

     Creating features via the API can be complex, given that there are many features with different features. The method I use, is to start is to create a simple model in Onshape, get the list of features, try updating / creating a feature or two.

    For example, this document has a cylinder: https://cad.onshape.com/documents/90b779a7c0d90369da933f4a/w/ea9036b3c8be03bf5519fc25/e/eb8e06c33f5da45b743264cd

    You can get the features using this API : https://cad.onshape.com/api/v6/partstudios/d/90b779a7c0d90369da933f4a/w/ea9036b3c8be03bf5519fc25/e/eb8e06c33f5da45b743264cd/features?rollbackBarIndex=-1&includeGeometryIds=false&noSketchGeometry=true 

    Now to update the Extrude depth, I get the feature corresponding to the Extrude and use this endpoint : 
    https://cad.onshape.com/documents/90b779a7c0d90369da933f4a/w/ea9036b3c8be03bf5519fc25/e/eb8e06c33f5da45b743264cd, featureID FPo5vUjLNxbM0Ie_0 and the body here : . Note the actual value changed was the expression from 500->400, but I need to specify all the other parameters as well.

    {
              "btType": "BTMParameterQuantity-147",
              "value": 0,
              "units": "",
              "isInteger": false,
              "expression": "400 mm",
              "parameterId": "depth",
              "nodeId": "hE+traOz1uXpwXTY"
    }


    Hope that helps.

  • lajos_szabó013lajos_szabó013 Member Posts: 10 EDU
    Dear Paul, 

    thank you for you answer. I do not really get it.

    After getting the list of the features from the part the PartStudio how can I formulate the data to make an update on any of the features? I mean you copied this to give all the parameters:

    {
              "btType": "BTMParameterQuantity-147",
              "value": 0,
              "units": "",
              "isInteger": false,
              "expression": "400 mm",
              "parameterId": "depth",
              "nodeId": "hE+traOz1uXpwXTY" 


    I do not know what these parameters are and what they mean. Like what is btType and why is it "BTMParameterQuantity-147"? Or how did you get the nodeId? I made this request ( https://cad.onshape.com/api/v6/partstudios/d/90b779a7c0d90369da933f4a/w/ea9036b3c8be03bf5519fc25/e/eb8e06c33f5da45b743264cd/features?rollbackBarIndex=-1&includeGeometryIds=false&noSketchGeometry=true ), in the respone there is no find for "hE+traOz1uXpwXTY".

    I do not know the meaning of this tons of parameter coming back as response. Also do not understand the connection between them and the body of an update request. 

    Anyway, I am a mechanical engineer trying to make some automation as a part of my MSc. thesis. I have some programming background, but I am not a programmer.

    Thank you for your time.
  • lajos_szabó013lajos_szabó013 Member Posts: 10 EDU
    Dear Paul, 

    I am getting closer, just successfully managed to change the extrusion depth of a cylinder.

    Firstly I did not really unterstand what this sentence was for in the API Usage Details section:

    "The feature access and modification API in Onshape presents the internal form of feature definitions rather than providing a translation layer between external form and internal form."

    If I understand right this is like having a form of a feature. A feature list request comes back containing not active parameters too with their default expression values, for example thickness or draft angle, even if the used feature is simple solid extrude.

    Furthermore, I now perceive like the API documentation contains more details. Maybe I read it hastily before, or you have indeed advanced it.

    Thank you again.
       
  • Andries_KoorzenAndries_Koorzen Member Posts: 2

    For anyone stumbling on this post (I'm an external developer and not part of Onshape):

    Internally Onshape has data models of the features.

    When a API REST response is returned, it contains the model of the feature.

    The data model of a feature includes (but is not limited to):

    • The feature data required to generate it using featurescript, the param is feature
    • The parameters for the feature itself parameters
    • The type of feature btType
    • Conditional: The dependent features to generate the feature featureIds

    I've attached a POSTman collection below. Read the comments carefully and it should generate sketches, fillets, extrudes

    (The collection does not include documentation on how to authenticate)

    The most important nugget of information is the queryString in step 11 (create mirror). It contains a query that returns an entity from a feature id. This should give you enough tools to use the API in combination with feature script queries to completely generate features in Onshape.

Sign In or Register to comment.