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.

Set a Part's Material via the REST API

Hillel_HochszteinHillel_Hochsztein Member, csevp Posts: 5 PRO
Hi,

I am using the REST API to update metadata properties for parts (using https://cad.onshape.com/glassworks/explorer/#/Metadata/updateWVEPMetadata) but I cannot set the material of the part.

Ostensibly, this is because unlike most other properties, where the 'value' field is a string, for the material metadata entry, the 'value' field's entry has its own schema (to include various material properties, etc).

Is there an endpoint for setting the material? Or even just a way to search and retrieve a material's entry from the material library (so that I could update the metadata manually)?

Answers

  • Caden_ArmstrongCaden_Armstrong Member Posts: 177 PRO
    I believe that there is no endpoint for setting the material, its just the update metadata endpoint. 

    There is a non-publicly documented endpoint for getting the materials list (proceed with caution, undocumented APIs can change without notice, etc etc)

    /api/materials/libraries/d/2718281828459eacfeeda11f/e/6bbab304a1f64e7d640a2d7d

    That is for the Onshape std material library. If your company has their own list, obviously you'd need to swap out the document/element ids.

    When you set the material metadata, I am pretty sure you only need to set the id of the material and the libraryReference.
    so like:

    "propertyId" : "57f3fb8efa3416c06701d615",
    value :{
    "id" : "Acrylic"
          "libraryReference" : {
            "elementId" : "6bbab304a1f64e7d640a2d7d",
            "documentId" : "2718281828459eacfeeda11f",
            "versionId" : "00551e3bfba06025872715c0",
            "elementMicroversionId" : "5c9010d279aaf0b434afbc4d"
          }
    }

    www.smartbenchsoftware.com --- fs.place --- Renaissance
    Custom FeatureScript and Onshape Integrated Applications
  • Hillel_HochszteinHillel_Hochsztein Member, csevp Posts: 5 PRO
    Hi,

    Thanks so much! That got me most of the way there. But I also need to pass the "libraryName" field (in this case it is "Onshape Material Library").
  • Hillel_HochszteinHillel_Hochsztein Member, csevp Posts: 5 PRO
    Update:

    This does not completely work. The material is assigned programatically (and is displayed in the part's properties window), but onshape errors out when looking at the mass properties. If I manually open the "Edit Material" dialogue, Onshape tells me that there is a new version of the material available and will not do things like calculate mass properties until I manually accept the update by pressing the check button. (then mass properties will solve).

    I've tried finding a more recent microversion of the Onshape Material Library document ('std.mat')  with no success. I've also tried omitting the "library reference" entirely and instead using "libraryName": "Onshape Material Library" which does work, but with the same issue.

    Looking at the metadata payload when I manually set the material, it is definitely formatted differently than what the material endpoint is feeding (instead of properties being a dictionary, it is a list where each material property is a dictionary of some matching schema) and when I push the material metadata programatically, it does not naturally build out the properties list.

    This all makes me wonder if Onshape doesn't want us to set material from the metadata endpoint, and hopefully they have a different endpoint specifically for setting part material (possibly also unpublished)
Sign In or Register to comment.