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 Category with Featurescript?

EvanReese
EvanReese Member, Mentor Posts: 3,086 PRO

I'm trying to change a part category via FS. Some properties (like "Not Revision Managed") don't autocomplete, but can be set anyway as a "CUSTOM" property with the property ID. I hoped to do the same thing for a Category. Here's what I'm trying, but it isn't working. Has anyone else proven whether or not this is possible?

        const categoryID = "57f3fb8efa3416c06701d625";
        const categorySelectionID = "6983854abad5b851116b0a88";
        
        setProperty(context, {
                "entities" : entities,
                "propertyType" : PropertyType.CUSTOM,
                "customPropertyId" : categoryID,
                "value" : categorySelectionID
        });
Evan Reese
The Onsherpa | Reach peak Onshape productivity
www.theonsherpa.com

Best Answer

Answers

  • EvanReese
    EvanReese Member, Mentor Posts: 3,086 PRO

    Everyone needs to hire this man 👆

    Evan Reese
    The Onsherpa | Reach peak Onshape productivity
    www.theonsherpa.com
  • Sam_Forster
    Sam_Forster Member Posts: 2 PRO

    I'm trying to do the same thing, assign a category using featurescript. I get this error:

    "Precondition of setProperty failed (definition.value is string)"

    // trying to assign the category
    const categoryString = "68c877ccca741af3fb44da75";
                    
    setProperty(context, {                            
      "entities" : part,                              
      "propertyType" : PropertyType.CUSTOM,                        
      "customPropertyId": "57f3fb8efa3416c06701d625",
      "value" : [ "\"" ~ categoryString ~ "\"" ]
    });
    
  • Caden_Armstrong
    Caden_Armstrong Member Posts: 468 PRO

    The brackets are part of the string. You need the exact format in my earlier post.

    www.smartbenchsoftware.com --- Renaissance --- Kestrel -- SmartLink
    Experts in Onshape Automation - Custom Features and Integrated Applications
  • wille_j
    wille_j Member Posts: 145 ✭✭✭
    edited May 13

    I'm looking at a computed part property FeatureScript and I'm trying to get the category. It seemed related to this thread.


    I have the code below but it doesn’t work.

    CATEGORY_ID is the custom property "Category" id. It don't seem to work with the category selection id either. Is there anything I'm missing?

    Thanks, Wille

    const CATEGORY_ID = "57f3fb8efa3416c06701d625";
    const category = getProperty(context, {
     "entity" : part,
     "propertyType" : PropertyType.CUSTOM,
     "customPropertyId" : CATEGORY_ID
     });
    
  • wille_j
    wille_j Member Posts: 145 ✭✭✭

    Update on the getProperty for category, I'm not doing anything wrong apparently. It is (currently) not supported.

  • EvanReese
    EvanReese Member, Mentor Posts: 3,086 PRO
    Evan Reese
    The Onsherpa | Reach peak Onshape productivity
    www.theonsherpa.com