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.

FeatureScript to update part appearance and name?

mbattistellombattistello Member, Developers Posts: 51 ✭✭
Is it possible to update a parts appearance/color and name using FeatureScript? I looked thru the docs and dont see a way. I also updated a part and checked the code and dont see where its showing up so Im guessing these types of changes are not considered features.

I am able to add in an attribute to the body but that doesnt seem to have any impact on the display. Maybe there is some attributes to specific to these values?

Comments

  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,211
    It is not currently possible, but hopefully we will have this in the not-too-distant future.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • mbattistellombattistello Member, Developers Posts: 51 ✭✭
    A related question. If I used setAttribute to set a value on a body is that value available in the API? I tried to find it but dont see it. I thought it might show in the feature list (/partstudios/d/:did/[wvm]/:wvm/e/:eid/features) but I dont see it. 

    If I can "tag" the body in FS then in the API I can make the appear and name using the API and a webhook. 
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,211
    It doesn't show up in the feature list, but you can get access to it from the API by using the evalFeatureScript API ( /partstudios/d/:did/[wvm]/:wvm/e/:eid/featurescript ) -- just pass a function that takes the context and reads/queries for attributes from it.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • mbattistellombattistello Member, Developers Posts: 51 ✭✭
    @ilya_baran could you help me with the featurescript to use in the api call?

    Im trying this but it doesnt work.

    {
        "script": "function(context is Context, queries){ return getAttribute( context,{ \"entities\": qEverything(EntityType.BODY)});}",
        "queries": []
    }
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,211
    The first thing I see is that the function name is getAttributes not getAttribute.  I would suggest testing the code first in a custom feature at the end of the part studio -- that will iron out issues with the FS.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • mbattistellombattistello Member, Developers Posts: 51 ✭✭
    I dont see a getAttribute in the docs? Only getAttributes - https://cad.onshape.com/FsDoc/library.html#module-attributes.fs

    I have a FS that sets the attributes and then I pull them and dump via println so they are getting set. Using API Explorer to try and get the FS correct but doesnt seem to work. I can get some of the sample code working.
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,211
    Yeah, that's what I am saying: your script above has "getAttribute" instead of "getAttributes".  There is no getAttribute in the library that I can see.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
Sign In or Register to comment.