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.

How to go from an enum in a UI to a value or specification?

jack_white396jack_white396 Member Posts: 7 EDU
Ok so I am fairly new and not great at featurescript, but I am making a feature that will generate metal tubing. So I have it to where the user selects from a few dropdown menus but I do not know how to make that selection determine the parameters for the part. Here is the feature as it stands-
FeatureScript 1803;
import(path : "onshape/std/geometry.fs", version : "1803.0");


export enum daave 
    {
        annotation {"Name" : "Thick Wall"}
        thiq,
        annotation {"Name" : "Thin Wall"}
        thin,
    }
export enum diive
    {
        annotation {"Name" : "1x1"}
        ONE,
        annotation {"Name" : "2x1"}
        TWO,
        annotation {"Name" : "2x2"}
        THREE,
    }

annotation { "Feature Type Name" : "Tube Generator" }
export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
     annotation {"Name" : "Dimensions"}
     definition.Dimensions is diive;
     
     annotation {"Name" : "Thickness"}
     definition.Thickness is daave;

     annotation { "Name" : "Length" }
     isLength(definition.myLength, LENGTH_BOUNDS);
    }
    {
        
        // Define the function's action
    });

Answers

  • carl_malagodicarl_malagodi Member Posts: 18 EDU
    This question is a little open ended but the general idea is that in the code block with (//define the function's actions) you'll probably end up with some control flow such as an if statement where you check the users input in a way similar to this (definition.Thickness == daave.thin),  this would evaluate to true if the user selected that option in their feature dialog and false if not. This seems to be the general way to change the behavior of your FS based on which selection was made in the dropdown menu.
  • MichaelPascoeMichaelPascoe Member Posts: 1,988 PRO
    edited August 2022
    Hi @jack_white396, here is one way you can do this. Also, check out this feature script course here.

    Tube Generator - MP - Onshape document 

    Fun fact: I did this on my phone.

    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   Learn How to FeatureScript Here 🔴
Sign In or Register to comment.