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.
Grouping Enum
Dylan_Stewart
Member, Developers Posts: 107 PRO
Okay so it's been a little while since I've deep in to FS and I have another hurdle to jump.
I am trying to group my enums instead of having a huge list.
I have a lot of different sketch profiles that will always be together when imported in. I have to separate them due to the complexity of the profile so each part will extrude correctly.
Is there a way to 'bypass' the need for this in the precondition?
What would be better is to be able to group all of the profiles that will be used in to 1 enumerator.
As always, your help is greatly appreciated.
I am trying to group my enums instead of having a huge list.
I have a lot of different sketch profiles that will always be together when imported in. I have to separate them due to the complexity of the profile so each part will extrude correctly.
annotation {"Feature Type Name": "Group Enum"} export const myGroupEnum = defineFeature(function(context is Context, id is Id, definition is map) precondition { annotation {"Name":"Profile1"} definition.profile_1 is 1profile; annotation {"Name":"Profile2"} definition.profile_2 is 2profile; annotation {"Name":"Profile3"} definition.profile_3 is 3profile; }PROFILES::import(importedDoc/123456.....) export enum 1profile { annotation {"Name":"1"} 123_0 } <pre class="CodeBlock"><code>export enum 2profile { annotation {"Name":"2"} 456_0 } <pre class="CodeBlock"><code>export enum 3profile { annotation {"Name":"3"} 789_0 }This example only uses 3 profiles but I imagine I will have somewhere in the neighborhood of around 20-30...
Is there a way to 'bypass' the need for this in the precondition?
What would be better is to be able to group all of the profiles that will be used in to 1 enumerator.
As always, your help is greatly appreciated.
Digital Engineering
0
Best Answer
-
mahir Member, Developers Posts: 1,307 ✭✭✭✭✭@Dylan_Stewart, I'm not sure what the desired end result is, but I don't see why you can't just code the desired behavior into a branched if/else based on an initial selection.
If (definition.profile =="123")
...import profiles 1, 2, 3
else if (definition.profile == "456")
...import profiles 4, 5, 6
else if (definition.profile == "789")
...import profiles 7, 8, 9
Another option is to group your profiles into an array of sub arrays that separates and organizes all the various profiles.
var profiles as array = [ [1a, 1b, 1c, 1d], [2a, 2b], [3a, 3b, 3c] ]
Then, depending on which enum is selected, you can load all the profiles in either profiles[1], profiles[2], or profiles,[3].3
Answers
Let us know if you have more questions!
Grouping all profiles would be ideal, as there may be some options later on down the line and that's when I would like to introduce the idea of the drop-down menu.
Basically, I need to build a group of profiles automatically while only using 1 option from the menu.
If (definition.profile =="123")
...import profiles 1, 2, 3
else if (definition.profile == "456")
...import profiles 4, 5, 6
else if (definition.profile == "789")
...import profiles 7, 8, 9
Another option is to group your profiles into an array of sub arrays that separates and organizes all the various profiles.
var profiles as array = [ [1a, 1b, 1c, 1d], [2a, 2b], [3a, 3b, 3c] ]
Then, depending on which enum is selected, you can load all the profiles in either profiles[1], profiles[2], or profiles,[3].
I believe this is going to be my solution. Thank you!!
PhD, Mechanical Engineering, Stanford University
You can use a lookup table to look up any FeatureScript value, not just numbers. You could even have that value be a FeatureScript map with many values inside.