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.

Replacing drawing reference through the API

MBartlett21MBartlett21 Member, OS Professional, Developers Posts: 2,050 ✭✭✭✭✭

Is there a documented way to update drawing references through the API?

I've tried both of the below:

  • POST /appelements/d/{did}/w/{wid}/e/{eid}/references/{refid}
    • The result was either "error generating query for deterministicId" or "An internal error has occurred; support code xxxx" or sometimes a message object about "must not be blank", depending on which parameters I tried to pass
  • POST/elements/d/{did}/w/{eid}/e/{eid}/updatereferences (seems like it should be the more correct way)
    • The result was always nothing, and it appeared to update the reference in the drawing, but the new reference always failed to resolve.

mb - draftsman - also FS author: View FeatureScripts
IR for AS/NZS 1100

Best Answer

  • Caden_ArmstrongCaden_Armstrong Member Posts: 195 PRO
    Answer ✓

    Actually, I played around with this a bit more and you can update references in some scenarios.
    I've only been able to get drawing references that reference the current document/workspace to go, but you can do a body like:

    POST /appelements/d/{did}/w/{wid}/e/{eid}/references/{refid}

    {
    "targetElementId": "3e1aaa9584e18f3f590b71d9"
    }
    Where only the targetElementId is modified.

    And the view/sheet reference will update to the new element, assuming everything is valid without changing the microversion of the document.
    I think a word of caution is appropriate here, I may have put the drawing into a broken state a few times messing around with this stuff.

    www.smartbenchsoftware.com --- fs.place --- Renaissance
    Custom FeatureScript and Onshape Integrated Applications

Answers

  • Caden_ArmstrongCaden_Armstrong Member Posts: 195 PRO

    My Renaissance app has a function that duplicates drawings and modifies the configurations to generate "configured" drawings.
    I'm using the endpoint:

    POST /appelements/d/{did}/w/{wid}/e/{eid}/references/{refid}

    and my body is:
    referenceId
    targetConfiguration

    From playing around with drawing references, most fields aren't supported.
    What in the reference are you trying to update?

    www.smartbenchsoftware.com --- fs.place --- Renaissance
    Custom FeatureScript and Onshape Integrated Applications
  • Caden_ArmstrongCaden_Armstrong Member Posts: 195 PRO
    Answer ✓

    Actually, I played around with this a bit more and you can update references in some scenarios.
    I've only been able to get drawing references that reference the current document/workspace to go, but you can do a body like:

    POST /appelements/d/{did}/w/{wid}/e/{eid}/references/{refid}

    {
    "targetElementId": "3e1aaa9584e18f3f590b71d9"
    }
    Where only the targetElementId is modified.

    And the view/sheet reference will update to the new element, assuming everything is valid without changing the microversion of the document.
    I think a word of caution is appropriate here, I may have put the drawing into a broken state a few times messing around with this stuff.

    www.smartbenchsoftware.com --- fs.place --- Renaissance
    Custom FeatureScript and Onshape Integrated Applications
  • MBartlett21MBartlett21 Member, OS Professional, Developers Posts: 2,050 ✭✭✭✭✭

    My idea was trying to duplicate drawings and then replace references, so that I could create a drawing with a particular view layout (rather than the default four views). I'll try trimming the reference updates down and see what that does for me.

    mb - draftsman - also FS author: View FeatureScripts
    IR for AS/NZS 1100
  • Caden_ArmstrongCaden_Armstrong Member Posts: 195 PRO

    I'm attempting the same thing. The difficulty is that if you duplicate your "template" drawing and transfer it to another document, the reference becomes a version reference…and I'm having trouble updating them.
    My workflow is:

    - Duplicate template drawing AND part studio tabs
    - Update the duplicated drawing references to the duplicated part studio
    - Do a "move tab to other document" including the referenced tab (this ensures that when it gets transferred into the destination document it becomes a microversion reference instead of a version reference)
    - Update the drawing to your desired final part references (should only require an elementId as before)
    - delete the extra part studio tab

    Its a lot of steps, but it works….

    www.smartbenchsoftware.com --- fs.place --- Renaissance
    Custom FeatureScript and Onshape Integrated Applications
  • eric_pestyeric_pesty Member Posts: 1,947 PRO

    When I do it manually, I do a "part out" of the drawing and reference, and then restore but I'm not sure you can do this through the API…

  • MBartlett21MBartlett21 Member, OS Professional, Developers Posts: 2,050 ✭✭✭✭✭
    edited November 22

    So far the reference updates are happy to include the targetConfiguration, targetElementId and idTag keys in order to change to another part, so I'm happy with that so far. Next step is to work out duplicating nicely…

    EDIT: Just the targetConfiguration, targetElementId and idTag seem to work fine to update from a version reference to a workspace reference. It seems I can't include a targetDocumentId, otherwise it also asks me for a targetVersionId. (this does appear to work for changing to a version reference as well)

    And it also appears to be happy to update to assembly references as well.

    And this is one of the nice errors that I got while testing (which seems to list out the fields that work)

    Target reference is not valid com.belmonttech.modeling.app.BTAppElementReferenceEntry@2582b125
    [configuration_=default
    ,deterministicIdConfiguration_=default
    ,deterministicIdMicroversionId_=a9487400185bec6f474366fd
    ,deterministicId_=JHD
    ,documentId_=f529c46a3baa04721a44e65f
    ,documentMicroversionId_=<null>
    ,elementId_=376501fe80aaa1e5c1b8c2b8
    ,isFlattenedPart_=false
    ,isLocked_=false
    ,isSketchOnly_=true
    ,isSurface_=false
    ,microversionId_=<null>
    ,occurenceId_=<null>
    ,partIdentity_=<null>
    ,partNumber_=<null>
    ,queryBelScriptVersion_=2506.0
    ,referenceId_=fc7d0d7c19679d7d504bf267
    ,referenceType_=PART
    ,revision_=<null>
    ,sketchIds_=<null>
    ,trackNewVersions_=true
    ,versionId_=7584b029e6af3b41a1e65003
    ]

    mb - draftsman - also FS author: View FeatureScripts
    IR for AS/NZS 1100
  • MBartlett21MBartlett21 Member, OS Professional, Developers Posts: 2,050 ✭✭✭✭✭

    Ok. Results.

    Updating assemblies seem to cause problems with the drawing. It all appears well, but stops working properly if you try to change configuration through the UI. (eventually results in not being able to use the sheets panel and getting 'Prior configuration failed to load. Not found.' when changing the configuration of the BOM.)

    This seems to happen whether you update the BOM references to the correct tab and configuration (retrieved with the bomelement API) or just leave them alone.

    Part drawings appear to be fine though.

    mb - draftsman - also FS author: View FeatureScripts
    IR for AS/NZS 1100
Sign In or Register to comment.