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.

Arbitrary drop-down menu?

adamohernadamohern Member, OS Professional Posts: 216 PRO
I want to include a list of standard sizes for a feature. How do I do that?

I see that the Extrude feature uses one for boundary type, but this appears to be a special case using globals. How do I assign arbitrary values to the dropdown menu items?
Tagged:

Comments

  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,210
    You can declare your own enum like this:
    export enum Size
    {
        annotation { "Name" : "Small" }
        SMALL,
        annotation { "Name" : "Medium" }
        MEDIUM,
        annotation { "Name" : "Large" }
        LARGE
    }
    
    annotation { "Feature Type Name" : "My Feature" }
    export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            annotation { "Name" : "Size" }
            definition.size is Size;
        }
        {
        }, { /* default parameters */ });
    


    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • adamohernadamohern Member, OS Professional Posts: 216 PRO
    Thank, Ilya. I guess what's confusing me is the use of the globals, in your case SMALL, MEDIUM, and LARGE. Where do those get defined, and kind of data should they be?
  • adamohernadamohern Member, OS Professional Posts: 216 PRO
    Sorry, reading up on enum objects here, and I think I understand. It's a really strange construct as I understand it. Apparently the all-caps assignment is interpreted as a string, but is also accessible as if it were a map key. It's like a map where the keys and values are identical. I wonder why it works this way.
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,210
    SMALL, MEDIUM, and LARGE are not globals -- they are enumeration values defined right inside the enum declaration (see https://en.wikipedia.org/wiki/Enumerated_type)
    Basically the declaration
    export enum Size
    {
        REALLY_SMALL,
        MEDIUM,
        TRULY_HUGE
    }
    defines a new enum type Size and says that a value of type Size may be one of three possible values: Size.REALLY_SMALL, Size.MEDIUM and Size.TRULY_HUGE.  See also https://cad.onshape.com/FsDoc/values.html#enumerations for specific info on how enums work "underneath" in FeatureScript .
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • adamohernadamohern Member, OS Professional Posts: 216 PRO
    Many thanks, Ilya.
Sign In or Register to comment.