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.

Simple C++ onshape STL export

billyzelsnackbillyzelsnack Member Posts: 87 PRO
edited January 2023 in General
I have written a minimal c++ example for exporting STL files from a partstudio that supports both API Keys and OAuth authorization. I am not a web developer and I found the onshape-public examples extremely confusing to follow. I ended up writing this from scratch from the documentation instead. It's available here: https://github.com/billyzelsnack/simple_onshape_exportstls

Comments

  • billyzelsnackbillyzelsnack Member Posts: 87 PRO
    edited January 2023
    I'm now trying to change it to use the /stl with the /partstudios call instead of the /parts call.
    I generate a list of partId via the /parts call as before

    Side note. Am I missing something that the Glassworks API Explorer can't actually test the stl calls because it needs to do a redirect?

    I can take a copy/paste a string from the API Explorer and stick it into my code that does the redirect and get an stl back of the entire model. This is that call:
    https://cad.onshape.com/api/v5/partstudios/d/bd9401ba05b5d74bf12bb1a6/w/998c0499cee6d8fc96af5cbf/e/ecd24da899ea1976c376c6e7/stl

    However, if I copy/paste from the API Explorer and enter (one or more) partId (that my /parts call gave me). Like this call:
    https://cad.onshape.com/api/v5/partstudios/d/bd9401ba05b5d74bf12bb1a6/w/998c0499cee6d8fc96af5cbf/e/ecd24da899ea1976c376c6e7/stl?partIds=partId%3DJLD%26partId%3DJRH

    I get this redirect:
    https://cad-usw2.onshape.com:443/modelexport?workspaceId=998c0499cee6d8fc96af5cbf&microversion=fb393aef1f4c43b2eb6d8a75&format=STL&mode=text&grouping=true&scale=1.0&units=inch&partIds=partId%3DJLD%26partId%3DJRH&_m=91affd80&documentId=bd9401ba05b5d74bf12bb1a6&elementId=ecd24da899ea1976c376c6e7
    Which does not give me an stl, but this:
    {
      "message" : "Not found.",
      "moreInfoUrl" : "",
      "status" : 404,
      "code" : 0
    }

    I've tried to add various combinations of the optional parameters too but it's always the same.
  • billyzelsnackbillyzelsnack Member Posts: 87 PRO
    I can now get parts individually if I leave off the partId=

    For example these two calls will give me stls for the two different parts:
    https://cad.onshape.com/api/v5/partstudios/d/bd9401ba05b5d74bf12bb1a6/w/998c0499cee6d8fc96af5cbf/e/ecd24da899ea1976c376c6e7/stl?partIds=JLD
    https://cad.onshape.com/api/v5/partstudios/d/bd9401ba05b5d74bf12bb1a6/w/998c0499cee6d8fc96af5cbf/e/ecd24da899ea1976c376c6e7/stl?partIds=JRH

    However if I try a list as described in explorer (why I thought that I needed the partId= to begin with) I just get the error from above.
    Here is the relevant section from API Explorer:
    IDs of the parts to retrieve. Repeat query param to add more than one (i.e. partId=JHK&partId=JHD). May not be combined with other ID filters

  • billyzelsnackbillyzelsnack Member Posts: 87 PRO
    edited January 2023
    ok. Figured it out. The multiple parts need to be comma separated. The example now supports individual files, a single combined stl, and a zip of the stls.
  • Leilena_TekleLeilena_Tekle Member, Onshape Employees Posts: 2
    @billyzelsnack This is a bug in the documentation and we are fixing it. We will let you know as soon as the changes are made. 
Sign In or Register to comment.