Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- 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?
adamohern
Member, OS Professional Posts: 216 PRO
Comments
-
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 Inc0 -
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?0
-
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.0
-
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 declarationexport 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 Inc0 -
Many thanks, Ilya.0

