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.

Working example on how to change custom property value in standard content and assembly item via API

gaphillgaphill Member Posts: 5 PRO
edited November 2021 in Community Support
My goal is to build very simple script based inventory management on top of Onshape Custom Properties. Hence, I need to change stock size and some other custom properties via API in all 3 types of items: normal parts, assembly items and standard content items.

I have created a test custom property named "unitprice", and a test assembly with one normal part, one assembly item and one standard content item.

There was no trouble in changing the value of "unitprice" via API with normal part.

The question is, how can I do the same with assembly item and with standard content item?

As you can see in picture of a BOM below, "unitprice" is visible in both.

API explorer (or Glassworks) have not been very helpful here. All combinations tried have ended up into 404.

Does anyone have a working example of these? What I need is basically understandable information how to construct api url and the request body

Or is it at all possible?











Answers

  • alan_baljeualan_baljeu Member, User Group Leader Posts: 111 ✭✭
    I'm interested to figure the answer to this question of yours.  I see in your output you are querying /api/items.  I don't see this documented in the Glassworks API explorer, nor in the developer portal documentation.  Where did you find this API?

    I'm also curious how you get the nice output format that you pasted here.

    Creating knowledge-driven design automation software, for molds, etc.
    www.virtualmold.com

  • gaphillgaphill Member Posts: 5 PRO
    edited December 2021
    Last question first: I simply copypaste the get request url to browser. The browser does the formatting. At least Firefox does.

    I made my test doc public so it's easier to discuss when the urls point to something.

    I start by describing what works, normal parts:

    Starting point is the assembly BOM. This  get-request gives the list of items in the assembly. Property id's can also be found in "headers" section if you so wish. Each normal-part-item has "itemSource" section where the did/wid/eid of the part studio and the partId can be found.

    Using the information we can then query the part metadata by this get-request, as documented in Glassworks. The useful piece of information in the response is the part href.

    Now it is possible to change our custom property by performing a post-request, as documented in Glassworks:

    url:  https://cad.onshape.com/api/metadata/d/f77a35101e278f65f22e1cf7/w/1f8b9ff1fa99327dde725ff5/e/87724ddfa5db6997ff541954/p/JJD

    body:
    {<br>    "items": [<br>        {<br>            "href": "https://cad.onshape.com/api/metadata/d/f77a35101e278f65f22e1cf7/w/1f8b9ff1fa99327dde725ff5/e/87724ddfa5db6997ff541954/p/JJD?configuration=default",<br>            "properties": [<br>                {<br>                    "propertyId": "618933bd0fc6dd59cc1a9e0b",<br>                    "value": "339.2"<br>                }<br>            ]<br>        }<br>    ]<br>}
    Works like a charm.



    Standard content is, however, a different beast. We can try the exactly same approach as above to form the post-request as documented:

    url:

    body:
    {<br>    "items": [<br>        {<br>            "href": "https://cad.onshape.com/api/metadata/d/f6acefc45b5cf9bf42197095/v/143e276ccee102ffbb3482aa/e/d2b2aadf45f6c5a78a3165b2/p/JHD?configuration=default",<br>            "properties": [<br>                {<br>                    "propertyId": "618933bd0fc6dd59cc1a9e0b",<br>                    "value": "290.3"<br>                }<br>            ]<br>        }<br>    ]<br>}



    This is naturally doomed to fail since the did/wid/eid here points to a part studio owned by Onshape. The customer-specific information must live somewhere else. Glassworks or API Explorer are not at all helpful here.



    With assembly items, the href starting with "/api/items" can be found from "itemSource" but the story ends there. No documentation whatsoever is available.


    Custom properties of standard content and assembly items can be however changed from the GUI. So at least there is a place for the information somewhere in the database.





    Sorry about the messy code blocks, I did not manage to find how to make them nicer. I did create code block first and the copypasted into it but it did not help much.
  • alan_baljeualan_baljeu Member, User Group Leader Posts: 111 ✭✭
    What you are looking for, I believe, is to set the configuration properties of a standard part which was added to your assembly.  You can't do this by sending a POST to the part studio defining the washer because that isn't your part.  

    So within the assembly document, you need to get the part instance element, and invoke /api/elements/d/{document}/w/{workspace}/e/{element}/configuration

    and to this you send your list of parameter values.  (ClearanceHole, OutsideDiameter, Thickness).

    Creating knowledge-driven design automation software, for molds, etc.
    www.virtualmold.com

  • gaphillgaphill Member Posts: 5 PRO
    I'm not very familiar with configurations, but I think the property is stored elsewhere. Why? The configuration of test doc is untouched:

    But I can still access custom proprety "Unit Price" via assembly BOM tab:


    This value is also visible in all other assemblies where the same part is present. Even in a different document. This makes one think  that the property is stored somewhere in a companywide place.
  • alan_baljeualan_baljeu Member, User Group Leader Posts: 111 ✭✭
    Configurations are confusing, I agree. But at bottom they are defined in a part studio and configured in each assembly that uses a configurable part.   These values are stored in each assembly where you configure the item. 
    Creating knowledge-driven design automation software, for molds, etc.
    www.virtualmold.com

Sign In or Register to comment.