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.
Translating a drawing using the API
shawn_crocker
Member, OS Professional Posts: 861 PRO
Best Answers
-
chadstoltzfus Member, Developers, csevp Posts: 139 PROThis 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).
Applications Developer at Premier Custom Built
chadstoltzfus@premiercb.com0 -
caden_armstrong2 Member, User Group Leader Posts: 127 ✭✭✭@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.3
Answers
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).
chadstoltzfus@premiercb.com
Thanks. I kept skipping over that one thinking a GET end point was what I needed.
- 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
chadstoltzfus@premiercb.com
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?
chadstoltzfus@premiercb.com
@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.
Oh that's really nice, I'll have to update my app with that.
chadstoltzfus@premiercb.com
Thanks for that!
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.