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.

OnShape API GET request for a gltf object for assemblies

earlgreyaromaearlgreyaroma Member Posts: 4 EDU
Hi,

is there a way to get a gltf object from a whole assembly (the parts should be displayed assembled) directly or with some tricks? I couldn't find anything in the glassworks explorer except for getting singular parts gltfs and my knowledge in web development and this kind of stuff is lacking. Thanks in advance.

Answers

  • Paul_J_PremakumarPaul_J_Premakumar Member, Onshape Employees Posts: 214
    Hi, 

     You can use the https://cad.onshape.com/glassworks/explorer#/Assembly/translateFormat  to export an assembly to GLTF. The format name is "GLTF", for example

    curl -X 'POST' \
      'https://cad.onshape.com/api/v5/assemblies/d/a270d298dcd5eddb8f8df87a/w/0f9427c5999a5208c1aaf723/e/97fbc083912b777dca988f90/translations' \
      -H 'accept: application/json;charset=UTF-8; qs=0.09' \
      -H 'Content-Type: application/json;charset=UTF-8; qs=0.09' \
      -H 'X-XSRF-TOKEN: 24Ps+OlFRwV4iXJeiFWsSQ==' \
      -d '{
      "allowFaultyParts": false,
      "angularTolerance": 0.01,
      "distanceTolerance": 0.01,
      "formatName": "GLTF",
      "importWithinDocument": true,
      "maximumChordLength": 0.01
    <span>}'</span>

    Hope that helps!
    Paul
  • earlgreyaromaearlgreyaroma Member Posts: 4 EDU
    Thank you very much. The translation part works perfect now. I can manually download a working gltf file now. But my initial goal is to get back a json similar to the get requests for the part and partstudio gltf objects. I've read on other threads that I can use this with the generated translation ID to get the data:


    But it returns a 403 response with a message saying I either don't have permissions or the file doesn't exist, which both is wrong. Or do I need to add something into the request body of the translation request? I will be very grateful if I could get further help.
  • Paul_J_PremakumarPaul_J_Premakumar Member, Onshape Employees Posts: 214
    edited April 2023
    You will need to set "importWithinDocument" : false to avoid downloading the file in the document.

    For example 
    curl -X 'POST' \
      'https://cad.onshape.com/api/v5/assemblies/d/a270d298dcd5eddb8f8df87a/w/0f9427c5999a5208c1aaf723/e/97fbc083912b777dca988f90/translations' \
      -H 'accept: application/json;charset=UTF-8; qs=0.09' \
      -H 'Content-Type: application/json;charset=UTF-8; qs=0.09' \
      -H 'X-XSRF-TOKEN: EXO5O05ZGmIgxM5hPQQtEg==' \
      -d '{
    "allowFaultyParts": false,
    "angularTolerance": 0.01,
    "distanceTolerance": 0.01,
    "formatName": "GLTF",
    "maximumChordLength": 0.01,
    "storeInDocument" : false
    }'
    
      Once you do this, the response will include a URL to poll for the status of the translation (the translation isn't instantaneous). Once the requestState is "Done" , you can use the `resultExternalDataIds` to download the data using the API , https://cad.onshape.com/glassworks/explorer#/Document/downloadExternalData.


     { "requestState" : "DONE", "requestElementId" : "97fbc083912b777dca988f90", "resultExternalDataIds" : [ "644a6a544029fb275b67b7f6" ], "versionId" : null, "documentId" : "a270d298dcd5eddb8f8df87a", "workspaceId" : "0f9427c5999a5208c1aaf723", "resultElementIds" : null, "resultDocumentId" : "a270d298dcd5eddb8f8df87a", "failureReason" : null, "resultWorkspaceId" : "0f9427c5999a5208c1aaf723", "name" : "Assembly 1", "id" : "644a6a523cb91475814d44fe", "href" : "https://cad.onshape.com/api/v5/translations/644a6a523cb91475814d44fe" }

     Note: resultExternalDataIds maps to fid in the downloadExternalData request. For more information: https://onshape-public.github.io/docs/translation/#general-translations
Sign In or Register to comment.