Adding part to assembly via API

johannes_3000
johannes_3000 Member Posts: 9 ✭

I am trying to add an assembly into another assembly via API. Trying out the REST call in glassworks i get an error saying i am using a microversion even though i am using a version:

This is the document I am pasting:

https://cad.onshape.com/documents/ba1fece8e8480bb1fa5c2089/v/6d2dabf62ee2588360f457fe/e/ab51836df1310fcc7922ea92


Error: response status is 400

Response body

Download

{  "message": "Microversions may not be used with linked document references",  "status": 400,  "code": 9999,  "moreInfoUrl": ""}

I also don't understand how that API call should work since it only specifies one part/assembly. Is it the target or the payload?

I also have tried the same in python wihtout success but thats a different topic. Lets get this glassworks example working first. Any pointers welcome, thank you!

Comments

  • Caden_Armstrong
    Caden_Armstrong Member Posts: 472 PRO

    It would help to know the body you are using for your request. Your body is probably the problem.
    I know you can do it with just:

    documentId
    versionId
    elementId
    isWholePartStudio=false
    isAssembly=true
    configuration={config if applicable}

    You might be adding extra parameters that you don't need to add. The API can be a bit fussy if you include unnecessary parameters

    www.smartbenchsoftware.com --- Renaissance --- Kestrel -- SmartLink
    Experts in Onshape Automation - Custom Features and Integrated Applications
  • johannes_3000
    johannes_3000 Member Posts: 9 ✭

    Ok, I didn't fill in anything besides the autofill option in the glassworks. Now it works with the additional payload parameters.

    Not able to get the inserted assembly to appear at a different location though - I am using:

    {
    "documentId": "5ec100e212a5fab5ff355415",
    "elementId": "883aca11d7be9449d88a79a6",
    "includePartTypes": [
    "PARTS"
    ],
    "transform" : [
    1, 0, 0, 0,
    0, 0, -1, 0,
    0, 1, 0, 1,
    0, 0, 0, 1
    ],
    "isAssembly": true,
    "versionId": "5aa8b24aaac7e7881e21e1f2"
    }

    Any hints, should this work?

  • johannes_3000
    johannes_3000 Member Posts: 9 ✭

    Thanks @Caden_Armstrong for the response, that helped. Just realizing that for a transform I probably have to use the occurrencetransforms.

    Can you advise on how to use it, what do i need from the payload and how do i determine path?

    {
    "isRelative": true,
    "occurrences": [
    {
    "fullPathAsString": "string",
    "headInstanceId": "string",
    "internalOccurrence": true,
    "occurrenceWithoutHead": "string",
    "occurrenceWithoutTail": "string",
    "parent": "string",
    "path": [
    "string"
    ],
    "rootOccurrence": true,
    "tailInstanceId": "string"
    }
    ],
    "transform": [
    0
    ]
    }

  • Caden_Armstrong
    Caden_Armstrong Member Posts: 472 PRO

    you're better off using "transformedinstances", inserted with a specific transform.
    If you insert and then transform it requires a bunch of extra API calls, where as the transformedinstances endpoint lets you do all your insertions/transforms in a single call. With Onshape's API limits that can make a big difference to your usage.

    www.smartbenchsoftware.com --- Renaissance --- Kestrel -- SmartLink
    Experts in Onshape Automation - Custom Features and Integrated Applications
  • johannes_3000
    johannes_3000 Member Posts: 9 ✭

    thanks!