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.

Translating a drawing using the API

shawn_crockershawn_crocker Member, OS Professional Posts: 789 PRO
I have been looking through the glassworks resource and am surprised that I can't find a way to create a translation of a drawing.  Is this really not possible?  My intent is to pull out a drawing into an image format or a pdf.
Tagged:

Best Answers

  • chadstoltzfuschadstoltzfus Member, Developers, csevp Posts: 128 PRO
    Answer ✓
    This endpoint is available under the Drawings tag in the API explorer. 


    We used to use this to mass export drawings as pdfs before Onshape introduced the batch export functionality. In the body of the request, just make sure you set the 'formatName' field to the translation format you want to use (a list can be requested using the translationFormats endpoint).
  • caden_armstrongcaden_armstrong Member, User Group Leader Posts: 127 PRO
    Answer ✓
    @shawn_crocker
    @chadstoltzfus
    You can do the translation without needing to create an element and delete it.

    If you specify "storeInDocument=false" in the body.
    Use the returned translation ID (once its finished translating)
    You can use: GET /documents/d/[did]/externaldata/[translationid] 
    you can get a stream of the file directly.

Answers

  • chadstoltzfuschadstoltzfus Member, Developers, csevp Posts: 128 PRO
    Answer ✓
    This endpoint is available under the Drawings tag in the API explorer. 


    We used to use this to mass export drawings as pdfs before Onshape introduced the batch export functionality. In the body of the request, just make sure you set the 'formatName' field to the translation format you want to use (a list can be requested using the translationFormats endpoint).
  • shawn_crockershawn_crocker Member, OS Professional Posts: 789 PRO
    @chadstoltzfus
    Thanks.  I kept skipping over that one thinking a GET end point was what I needed.
  • chadstoltzfuschadstoltzfus Member, Developers, csevp Posts: 128 PRO
    Oh yeah I forgot to mention, doing this will indeed create a PDF element in your document, which might not always be desired. If you want your application to just "grab a PDF" of the drawing and not have it create any PDFs in your document, you can simulate that behavior by doing the following:

    - Use the drawing translation endpoint to create the translation (creates a PDF element in the document the drawing is in)
    - Use the blob elements endpoint to get the base64 string of the PDF element in the document
    - Decode the base64 and download/export as needed in your application
    - Then use the delete element endpoint to remove the PDF element
  • shawn_crockershawn_crocker Member, OS Professional Posts: 789 PRO
    @chadstoltzfus
    Thanks again.  I will follow that procedure.  So creating a translation of a released drawing works and the pdf element moves up into the workspace?
  • chadstoltzfuschadstoltzfus Member, Developers, csevp Posts: 128 PRO
    That's a great question, I should have mentioned that I don't work with release management because of the way we classify parts so I'm not quite sure. I would imagine based on the URL structure that it would have to work that way because you can use a version in the request, and since versions are immutable it wouldn't be able to create a new element in the referenced version. That's just a guess, though.
  • caden_armstrongcaden_armstrong Member, User Group Leader Posts: 127 PRO
    Answer ✓
    @shawn_crocker
    @chadstoltzfus
    You can do the translation without needing to create an element and delete it.

    If you specify "storeInDocument=false" in the body.
    Use the returned translation ID (once its finished translating)
    You can use: GET /documents/d/[did]/externaldata/[translationid] 
    you can get a stream of the file directly.
  • chadstoltzfuschadstoltzfus Member, Developers, csevp Posts: 128 PRO
    @caden_armstrong
    Oh that's really nice, I'll have to update my app with that. 
  • shawn_crockershawn_crocker Member, OS Professional Posts: 789 PRO
    @caden_armstrong
    Thanks for that!
  • shawn_crockershawn_crocker Member, OS Professional Posts: 789 PRO
    @shawn_crocker
    @chadstoltzfus
    You can do the translation without needing to create an element and delete it.

    If you specify "storeInDocument=false" in the body.
    Use the returned translation ID (once its finished translating)
    You can use: GET /documents/d/[did]/externaldata/[translationid] 
    you can get a stream of the file directly.
    Hi @caden_@caden_armstrong
    I have finally got the time to dig into getting drawing translations working.  I have successfully got the translation part working.  I have had success with "storeInDocument=true" and with "storeInDocument=false".  When using "false", I can find the "id" in the returned data but I am not able to get a stream of the file.  I get a "Resource does not exist, or you do not have permission to access it.".  I pretty certain this isn't the permission part of the message because using the same credentials, I am interacting with other parts of the API.  Her is the exact endpoint I am forming.

    https://cad.onshape.com/api/v5/documents/d/29da4d254bbab3f7b8a7431f/externaldata/636fa71337b6be47af2961fd

    I would be grateful for some more of your insights into this.  I also notice, every time I perform a new translation(for the same did/w/wvid/eid), the returned id is the same.  Seems strange to me.
  • shawn_crockershawn_crocker Member, OS Professional Posts: 789 PRO
    I discovered my problem.  I need to call the status of the translation and then use the "resultExternalDataIds" from that call when the status is "DONE"
Sign In or Register to comment.