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.
Conditional range selections
murat_bakkal
Member Posts: 7 PRO
Hello everyone,
I am trying to build a screw generator. I want to extract information from three tables that have different classes of diameters and for each diameter, there is a range of screw lengths that the user can choose from. This is one of the tables:
Depending on the selection of the screw type and screw diameter (which is dependent on the screw type), I would like to show to the user, only the relevant range of screw lengths. What I want to achieve is to get a set of variables from the user, like screw diameter, screw length, screw head size and so on.
My initial idea for the precondition is like this:
and so on. The same would be done for the other two classes of screws. Inside the program function, I would construct the same structure of if statements and assign the values of the selections to one common variable (for example screwDia or screwLength).
I found myself exporting and defining an enum for each and every specific case. I am new to Feature Script and a novice programmer but this did not feel right to me. First of all, I am showing a different enum to the user for the same information (screwLength variable) and under the same label which feels like "cheating". Furthermore, every time I change a more general condition (like screw type selection) the dependent selection range resets its value because it is actually a different annotation. I would very much prefer to keep this value as long as possible to give flexibility to the user.
Is there a way to make an enum change its form conditionally? I tried to move my if statements inside the "export enum ScrewDia" bit so that the enum structure would change its' values and tags by itself but that did not work. Is there an appropriate syntax for this?
I have also read from the forums that a look-up table would be a more suitable way to approach this but I could not adapt example codes to this specific case. Could someone please show me how the general structure for a look-up table for this particular case should look like?
Cheers.
Murat BAKKAL
I am trying to build a screw generator. I want to extract information from three tables that have different classes of diameters and for each diameter, there is a range of screw lengths that the user can choose from. This is one of the tables:
Depending on the selection of the screw type and screw diameter (which is dependent on the screw type), I would like to show to the user, only the relevant range of screw lengths. What I want to achieve is to get a set of variables from the user, like screw diameter, screw length, screw head size and so on.
My initial idea for the precondition is like this:
annotation { "Name" : "Screw type", "UIHint" : "SHOW_LABEL" }
definition.screwType is ScrewType; // exported ScrewType enum that has 3 selections
if (definition.screwType == ScrewType.fpan)
{
annotation { "Name" : "Screw dia", "UIHint" : "SHOW_LABEL" }
definition.screwDiamFPH is ScrewDiaFPH; // diameter classes for this type of screw
if (definition.screwDiamFPH == ScrewDiaFPH.twotwo) // if 2.2 dia screw is chosen
{
annotation { "Name" : "Screw Length", "UIHint" : "SHOW_LABEL" } // show the enum for this spec. range
definition.fPTwoTwoL is fPTwoTwoLengths;
}
if (definition.screwDiamFPH == ScrewDiaFPH.twofive)
{
annotation { "Name" : "Screw Length", "UIHint" : "SHOW_LABEL" }
definition.fPTwoFiveL is fPTwoFiveLengths;
}
if (definition.screwDiamFPH == ScrewDiaFPH.threezero)
{
annotation { "Name" : "Screw Length", "UIHint" : "SHOW_LABEL" }
definition.fPThreeL is fPThreeLengths;
}
and so on. The same would be done for the other two classes of screws. Inside the program function, I would construct the same structure of if statements and assign the values of the selections to one common variable (for example screwDia or screwLength).
I found myself exporting and defining an enum for each and every specific case. I am new to Feature Script and a novice programmer but this did not feel right to me. First of all, I am showing a different enum to the user for the same information (screwLength variable) and under the same label which feels like "cheating". Furthermore, every time I change a more general condition (like screw type selection) the dependent selection range resets its value because it is actually a different annotation. I would very much prefer to keep this value as long as possible to give flexibility to the user.
Is there a way to make an enum change its form conditionally? I tried to move my if statements inside the "export enum ScrewDia" bit so that the enum structure would change its' values and tags by itself but that did not work. Is there an appropriate syntax for this?
I have also read from the forums that a look-up table would be a more suitable way to approach this but I could not adapt example codes to this specific case. Could someone please show me how the general structure for a look-up table for this particular case should look like?
Cheers.
Murat BAKKAL
0
Best Answer
-
NeilCooke Moderator, Onshape Employees Posts: 5,683What you need is a lookupTable. See the hole feature for an example.
Are the screws you are trying to create not included in out Standard Content?Senior Director, Technical Services, EMEAI6
Answers
Are the screws you are trying to create not included in out Standard Content?
https://cad.onshape.com/documents/12312312345abcabcabcdeff/w/a855e4161c814f2e9ab3698a/e/daec16bcbf3755b1bc852153
Have fun!