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?

EvanReeseEvanReese Member, Mentor Posts: 2,932 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

  • EvanReeseEvanReese Member, Mentor Posts: 2,932 PRO

    Everyone needs to hire this man 👆

    Evan Reese
    The Onsherpa | Reach peak Onshape productivity
    www.theonsherpa.com
  • Sam_ForsterSam_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_ArmstrongCaden_Armstrong Member Posts: 440 PRO

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

    www.smartbenchsoftware.com --- Renaissance --- fs.place
    Experts in Onshape Automation - Custom Features and Integrated Applications
  • wille_jwille_j Member Posts: 60 ✭✭✭
    edited 10:31AM

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

    const CATEGORY_ID = "57f3fb8efa3416c06701d625";
    const category = getProperty(context, {
     "entity" : part,
     "propertyType" : PropertyType.CUSTOM,
     "customPropertyId" : CATEGORY_ID
     });
    

    Where 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

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.