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.

Options

API - Trying to find a more efficient way to pull thumbnails for each BOM item.

shawn_crockershawn_crocker Member, OS Professional Posts: 810 PRO
ATM, I pull a BOM through the API.  Probably due to lack of knowledge, I create a string using data contained in the JSON file for each item in the BOM that represents an end point to get the metadata for that item.  I include thumbnail in that GET request.  Now, the thumbnails included in the request are URLS and they work only if I am signed in to onshape.  Makes sense.  They don't work when being used by the retool app I am making.  I'm sure I could somehow get onshape to authenticate the app or something.  Before going that route, I am also able to send out another thumbnail request using that URL and receive a base64 image.  That image works fine use the authentication I currently have working.  My problem really is that I have to make three calls to get what I want.  Call the BOM, call the meta data, then call the actual base64 image.  Anyone know of a more efficient way?  I was really hoping the BOM call could just provide an option like the metadata call to include thumbnails potentially removing those other two calls.  What has got me thinking this could be better is watching openBOM videos.  When openBOM pulls a BOM with thumbnails, it seems to load everything in fairly fast.  For me, a BOM with 30 items will probable take about a minute I think.

I would be able to skip pulling the metadata and just construct a URL from the BOM data to pull the base64 thumbnail right off but I am not seeing a thumbnail get request that supports configurations and either workspaces or version.  In fact, any thumbnail get request that supports configurations seems to have to be of a workspace.
Tagged:

Answers

  • Options
    caden_armstrongcaden_armstrong Member, User Group Leader Posts: 127 ✭✭✭
    Seems like you have a few problems:
    1. Speed: Going from Bom to Thumbnail is pretty much going to require 3 calls. The reason openBOM is faster is likely due to parallelism. Getting every thumbnail simultaneously is going to be much faster than getting them one by one, even if you could somehow cut down the number of api calls per thumbnail. 

    2. If you want to get an image of an element in a configuration, you'll probably have to use the /shadedviews under either part studio or assembly endpoint.
    I think thumbnails are meant for menus, and thus only the minimum is created/cached.

    3. Authenticated your app is essential. The URLs for thumnail and metadata work in the browser because you session is authenticated with onshape, which doesn't work if you are automating. Onshape has documentation on how to use either API keys, which is the simple way, or OAuth  which is a requirement for the app store/ using with multiple users. If you want to make an extension, you'll have to go the OAuth route.
    Luckily, Onshape has some public repos with starter code in them, so you could just clone the project in your language of choice and start there.

  • Options
    shawn_crockershawn_crocker Member, OS Professional Posts: 810 PRO
    edited August 2022
    Thanks @caden_armstrong
    What has me stuck ATM is the authentication.  I have decided to try and get retool authenticated to be able to display the href urls that come in with the metadata call.  As we know, url works in the browser when I have an active onshape session but not from within retool because onshape is seeing the request for the image as coming from a source outside of the scope of the active session.  Retool is authenticating with onshape using keys right now.  In retool, I am assigning the metadata thumbnail urls into an image column.  I'm not sure how to authenticate these urls because retool is not performing a call where authentication would get passed.  Not sure if I'm making my issue clear.

    I would really like to pull shaded view images.  Problem with that is depending on how big the part or assembly is, the item can either be cutoff or really small in the middle of the image.  The image seems to always be out of center as well.
  • Options
    caden_armstrongcaden_armstrong Member, User Group Leader Posts: 127 ✭✭✭
    I've never used Retool, but you should be able to add your API keys to the header of your requests.

    How are you specifying the view matrix for shaded views?
    You might need to set the pixelSize value using the /boundingbox values to ensure that your view contains the entire part studio
  • Options
    shawn_crockershawn_crocker Member, OS Professional Posts: 810 PRO
    I've never used Retool, but you should be able to add your API keys to the header of your requests.
  • Options
    shawn_crockershawn_crocker Member, OS Professional Posts: 810 PRO
    I've never used Retool, but you should be able to add your API keys to the header of your requests.

    How are you specifying the view matrix for shaded views?
    You might need to set the pixelSize value using the /boundingbox values to ensure that your view contains the entire part studio
    Had to post the above because I don't know how to get out of the quote box if I accidentally place my cursor there without having typed any text outside the box first.

    So, the issue I'm having with the authorization is because the URLs are being used directly as a column value in an image column.  In retool you can supply a url to an image column and the table cell will display the image.  So there doesn't seem to be a way to provide authentication like this because I'm not actually sending a GET request that would have authentication in a header.
    Anyways, I am proceeding with just making that extra call to retrieve the base64 image.  I found another way of working my data so that the BOM comes in and gets processed in other ways quickly and allows the user to continue with other things while the thumbnails just keep getting called and populated at the same time.

    As for shaded views, I'm not sure what you mean about the bounding box
Sign In or Register to comment.