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.

shared predicate definition with slight differences

Evan_ReeseEvan_Reese Member Posts: 2,060 PRO
I'm trying to get between. In this case, I'm trying to write one predicate for my Cone and Prism features. The only difference between them is the definition.sides number for the prism. How can I write this only once, and hide that field on the Cone feature but show it on Prism? Link below to see what I'm trying to do.

https://cad.onshape.com/documents/a81f647d405a78c5b70bdbde/w/cb4099ea5a4f73db91ad5b5b/e/b82bd38a9390b4dd3155b161
Evan Reese / Principal and Industrial Designer with Ovyl
Website: ovyl.io

Best Answer

  • chadstoltzfuschadstoltzfus Member, Developers, csevp Posts: 130 PRO
    Answer ✓
    It looks like you went for sending an "isPrism" argument to the predicate, which should work. You could also set a key/value pair in the precondition of Prism feature and have the predicate do a check to see if that key is defined in the definition map. 
    Applications Developer at Premier Custom Built
    chadstoltzfus@premiercb.com

Answers

  • chadstoltzfuschadstoltzfus Member, Developers, csevp Posts: 130 PRO
    Answer ✓
    It looks like you went for sending an "isPrism" argument to the predicate, which should work. You could also set a key/value pair in the precondition of Prism feature and have the predicate do a check to see if that key is defined in the definition map. 
    Applications Developer at Premier Custom Built
    chadstoltzfus@premiercb.com
  • Evan_ReeseEvan_Reese Member Posts: 2,060 PRO
    edited September 2021
    It looks like you went for sending an "isPrism" argument to the predicate, which should work. You could also set a key/value pair in the precondition of Prism feature and have the predicate do a check to see if that key is defined in the definition map. 
    Thanks, Chad. I wasn't able to get the isPrism argument working for some reason. I'm not 100% sure I know what you mean about setting the key/value pair in the precondition. Can you clarify that for me a bit?

    Here's what I ended up doing which worked, but I'm guessing there's a cleaner way.

    in both preconditions (Cone and Prism) I added this:
            annotation { "Name" : "isPrism", "UIHint" : UIHint.ALWAYS_HIDDEN, "Default" : true }
            definition.isPrism is boolean;
            
            twoEndedPrimitivePredicate(definition);
    With the default set true in Prism and false in Cone. Then I made the "sides" field conditionally visible with 
    if (definition.isPrism)


    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
  • chadstoltzfuschadstoltzfus Member, Developers, csevp Posts: 130 PRO
    Yeah that solution looks good to me. There might be a way with less lines of code but I personally do like this method, feels pretty readable while not infringing on the UX in any way. 

    When I say key/value pair in the precondition I really mean another parameter. As you're probably aware, a feature definition is nothing more than a map, and maps consist consist of key/value pairs. Ex:

    var definition = {
         "key" : value
    };
    So in this specific use case the key/value pair being used is "isPrism"/true. 

    In my mind when dealing with predicates talking about a definition more like a map than a UI element makes sense because predicates are a more granular level of what the precondition (UI code block) of a custom feature entails. 
    Applications Developer at Premier Custom Built
    chadstoltzfus@premiercb.com
  • Evan_ReeseEvan_Reese Member Posts: 2,060 PRO
    Thanks, that helps. So you did mean to add a hidden param of some kind to reference.
    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
Sign In or Register to comment.