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.

Getting UnicodeDecodeError calling /drawings/d/{did}/externaldata/{tid] when translating drawings?

lebenitolebenito Member Posts: 15
When I call this call I get this UnicodeDecode Error in the Onshape Python API client.

  File "C:\Users\benne\AppData\Local\pypoetry\Cache\virtualenvs\lcb-7JzeowoO-py3.9\lib\site-packages\onshape_client\oas\api_client.py", line 421, in request
    return self.rest_client.GET(
  File "C:\Users\benne\AppData\Local\pypoetry\Cache\virtualenvs\lcb-7JzeowoO-py3.9\lib\site-packages\onshape_client\oas\rest.py", line 324, in GET
    return self.request(
  File "C:\Users\benne\AppData\Local\pypoetry\Cache\virtualenvs\lcb-7JzeowoO-py3.9\lib\site-packages\onshape_client\oas\rest.py", line 264, in request
    r.data = r.data.decode("utf8")
  UnicodeDecodeError: 'utf-8' codec can't decode byte 0x84 in position 261: invalid start byte

It only happens when I translate a drawing, not a partstudio. When I manually call this in my browser where I am logged into Onshape, the PDF export functions fine, but the configuration of the drawing is not changed (still the default one).
Is something wrong with my API call? My body looks like this:

           {
                'formatName': 'PDF',
                'storeInDocument': False,
                'configuration': config,
            }

The configuration works when translating the PartStudio of which the drawing is made and exporting its stl.
Different formats like dwg work, but also not with the right configuration.
Do translations work differently? And why the UnicodeDecodeError? I am not even trying to get the data of the request nor trying to print it.





Answers

  • shawn_crockershawn_crocker Member, OS Professional Posts: 866 PRO
    I know a small amount about the API system. I don't really know much about the code you have presented but I don't think you should have any config parameter when translating a drawing. Only a did,wvm,wvmid,eid.
  • lebenitolebenito Member Posts: 15
    Are you sure? But how are you then supposed to translate into a different configuration? The glassworks explorer also put into the parameter body:

    POST ​/drawings​/d​/{did}​/{wv}​/{wvid}​/e​/{eid}​/translations
    {
      "allowFaultyParts": true,
      "angularTolerance": 0,
      "blobElementId": "string",
      "blobMicroversionId": "string",
      "cloudObjectId": "string",
      "cloudStorageAccountId": "string",
      "colorMethod": "string",
      "configuration": "string",
      "connectionId": "string",
      "createComposite": true,
      "currentSheetOnly": true,
      "destinationName": "string",
      "distanceTolerance": 0,
      "elementId": "string",
      "elementIds": [
        "string"
      ],
      "emailLink": true,
      "emailMessage": "string",
      "emailSubject": "string",
      "emailTo": [
        "string"
      ],
      "extractAssemblyHierarchy": true,
      "flatten": true,
      "flattenAssemblies": true,
      "foreignId": "string",
      "formatName": "string",
      "fromUserId": "string",
      "getyAxisIsUp": true,
      "grouping": true,
      "imageHeight": 0,
      "imageWidth": 0,
      "importInBackground": true,
      "importWithinDocument": true,
      "includeExportIds": true,
      "joinAdjacentSurfaces": true,
      "level": "string",
      "linkDocumentId": "string",
      "linkDocumentWorkspaceId": "string",
      "maximumChordLength": 0,
      "notifyUser": true,
      "onePartPerDoc": true,
      "originalForeignId": "string",
      "parentId": "string",
      "partIds": "string",
      "password": "string",
      "passwordRequired": true,
      "processedForeignId": "string",
      "projectId": "string",
      "proxyDocumentId": "string",
      "proxyElementId": "string",
      "proxyWorkspaceVersion": "string",
      "proxyWorkspaceVersionId": "string",
      "selectablePdfText": true,
      "sendCopyToMe": true,
      "sheetIndices": [
        0
      ],
      "showOverriddenDimensions": true,
      "sourceName": "string",
      "specifyUnits": true,
      "splinesAsPolylines": true,
      "splitAssembliesIntoMultipleDocuments": true,
      "stepVersionString": "string",
      "storeInDocument": true,
      "textAsGeometry": true,
      "triggerAutoDownload": true,
      "unit": "string",
      "uploadId": "string",
      "validForDays": 0,
      "versionString": "string"
    }
    And it also does not give me a illegal Parameter or something as a respond and also does spit out a pdf, just not in the right configuration and with this weird python error (which does not come from my code but the oneshape api python client) :(

  • raj_Onshaperaj_Onshape Onshape Employees Posts: 110
    Onshape drawings do not have configuration.  Are you trying to change configuration of all view references and then export the drawing ?
  • lebenitolebenito Member Posts: 15
    @raj_Onshape Yes this is pretty much exactly what I am trying! With the configuration Parameter in the body of the POST translate drawing call, some other forum post I read and the other stuff when creating a drawing of a Part I just thought that would be exactly for that.
    Is there any other way? Or do I have to first create a whole new drawing with the api with the changed configuration?
    Thanks for the answer though!
  • shawn_crockershawn_crocker Member, OS Professional Posts: 866 PRO
    @raj_Onshape
    I am wonder if this is actually possible somehow as well.  To update all drawing views in a drawing to a different config using the api.
  • caden_armstrong2caden_armstrong2 Member, User Group Leader Posts: 127 ✭✭✭
    @shawn_crocker
    I can do this with my app Renaissance. It can duplicate a drawing and updates all of the views to a different configuration.

    https://appstore.onshape.com/apps/Utilities/XRQODIZXYFFSR7TEFILBKVQH5XWN6JAQRSTFWRY=/description
  • shawn_crockershawn_crocker Member, OS Professional Posts: 866 PRO
    @caden_armstrong
    This looks really great!  I know it is a bit much to ask but would you share approx. what are the key end points you use to modify drawing config references after the element is duplicated?  I'm guessing you are creatively combining a few different ones Because I am not immediately seeing any end points that will obviously do this.  I realize you have an app and such but I am really hoping to accomplish just the drawing updating within an app we already use.
  • caden_armstrong2caden_armstrong2 Member, User Group Leader Posts: 127 ✭✭✭
    @shawn_crocker
    I think the endpoint your are probably missing is  element references. Views/tables have a reference object, and I just update the configuration of each.
  • shawn_crockershawn_crocker Member, OS Professional Posts: 866 PRO
    @caden_armstrong
    Gotcha.  Thanks for that!
Sign In or Register to comment.