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