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.

if statement in precondition based on an enum

Emily_Qi_WangEmily_Qi_Wang Member Posts: 13 EDU
Hi,

I'm trying to merge two Features into one (i.e. both of these Features were prototyped on their own and involve part joinery, and the user wants to be able to swap between them within the dialog). Thus, I am trying to do something similar to what is happening in hole.fs: based on what the user has selected in the drop down menu, show a particular set of input boxes. 

However the code I have thus far is resulting in a precondition failure; a generic version of my code is included below. I did a quick comparison with what is going on in hole.fs and don't see any obvious differences in the approach. The same if statement is fine in the FeatureScript beyond the precondition (prototyped this if statement in the code beyond before I tried the if statement in the precondition). The documentation for enum doesn't provide any help with this. Am I missing something simple with this setup??

(Also, the <code></code> tag seems to mess up the spacing when I preview, so this isn't in a code block...)


FeatureScript 307;
import(path : "onshape/std/geometry.fs", version : "307.0");

export enum ChooseFeatureAB
{
    annotation { "Name" : "Feature A" }
    FEATUREA,
    annotation { "Name" : "Feature B" }
    FEATUREB
}

annotation { "Feature Type Name" : "Feature AB" }
export const FeatureAB = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
        annotation {"Name" : "Choose Option A or B",  "UIHint" : "REMEMBER_PREVIOUS_VALUE"}
        definition.chooseAB is ChooseFeatureAB; 

        if (definition.chooseAB as string == "FEATUREA") // tried this with if (ChooseFeatureAB as string == "FEATUREA"), which also resulted in a precondition failure
        {
            annotation { "Name" : "Feature A Length"}
            isLength(definition.featureALength, LENGTH_BOUNDS);

            annotation { "Name" : "Feature A # of Units"}
            isInteger(definition.featureAUnits, POSITIVE_COUNT_BOUNDS);

            // list of inputs continues...

        } else if (definition.chooseAB as string =="FEATUREB")
        {
            annotation { "Name" : "Feature B Checkbox" }
            isLength(definition.featureBCheckbox, LENGTH_BOUNDS);

            // list of inputs continues...
        }
    }

Best Answer

Answers

Sign In or Register to comment.