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.
condition in the if statement is failing
Mohamed_Ahmed_LT
Member Posts: 6 PRO
I am using the following script to create a three-stepped cylinder, I want the diameter for step 1 and 2 to depend on the selected value of dia3 from the lookup table/sizeTable. The condition in the if statement is failing though! can someone provide some guidance?
FeatureScript 2144;
FeatureScript 2144;
import(path : "onshape/std/common.fs", version : "2144.0");
export const sizeTable = {
"name" : "dia3",
"displayName" : "Dia3",
"default" : "25",
"entries" : {
"25" : {
"name" : "StockHeight",
"displayName" : "StockHeight",
"default" : "140",
"entries" : {
"60" : 60 * millimeter,
"100" : 100 * millimeter,
"127" : 127 * millimeter,
"140" : 140 * millimeter
}
},
"20" : {
"name" : "StockHeight",
"displayName" : "StockHeight",
"default" : "125",
"entries" : {
"60" : 60 * millimeter,
"84" : 84 * millimeter,
"104" : 104 * millimeter,
"125" : 125 * millimeter
}
}
}
};
annotation { "Feature Type Name" : "Tool4" }
export const tool4 = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
annotation { "Name" : "Tool height", "Lookup Table" : sizeTable }
definition.sizeTable is LookupTablePath;
if (definition.sizeTable.dia3=="25")
{
annotation { "Name" : "Dia1" }
isLength(definition.dia1, { (millimeter) : [1, 14, 14] } as LengthBoundSpec);
annotation { "Name" : "Dia2" }
isLength(definition.dia2, { (millimeter) : [14, 16, 19] } as LengthBoundSpec);
}
annotation { "Name" : "height1" }
isLength(definition.height1, { (millimeter) : [1, 20, 100] } as LengthBoundSpec);
annotation { "Name" : "height2" }
isLength(definition.height2, { (millimeter) : [1, 20, 100] } as LengthBoundSpec);
}
0
Comments
-
FeatureScript 2144; import(path : "onshape/std/common.fs", version : "2144.0"); export const sizeTable = { "name" : "dia3", "displayName" : "Dia3", "default" : "25", "entries" : { "25" : { "name" : "StockHeight", "displayName" : "StockHeight", "default" : "140", "entries" : { "60" : 60 * millimeter, "100" : 100 * millimeter, "127" : 127 * millimeter, "140" : 140 * millimeter } }, "20" : { "name" : "StockHeight", "displayName" : "StockHeight", "default" : "125", "entries" : { "60" : 60 * millimeter, "84" : 84 * millimeter, "104" : 104 * millimeter, "125" : 125 * millimeter } } } }; annotation { "Feature Type Name" : "Tool4","Editing Logic Function":"tool4EditLogic" } export const tool4 = defineFeature(function(context is Context, id is Id, definition is map) precondition { annotation { "Name" : "showDia1","UIHint":UIHint.ALWAYS_HIDDEN } definition.showDia1 is boolean; annotation { "Name" : "showDia2","UIHint":UIHint.ALWAYS_HIDDEN } definition.showDia2 is boolean; annotation { "Name" : "Tool height", "Lookup Table" : sizeTable } definition.sizeTable is LookupTablePath; if (definition.showDia1 ) { annotation { "Name" : "Dia1" } isLength(definition.dia1, { (millimeter) : [1, 14, 14] } as LengthBoundSpec); } if(definition.showDia2) { annotation { "Name" : "Dia2" } isLength(definition.dia2, { (millimeter) : [14, 16, 19] } as LengthBoundSpec); } annotation { "Name" : "height1" } isLength(definition.height1, { (millimeter) : [1, 20, 100] } as LengthBoundSpec); annotation { "Name" : "height2" } isLength(definition.height2, { (millimeter) : [1, 20, 100] } as LengthBoundSpec); } { }); export function tool4EditLogic(context is Context, id is Id, oldDefinition is map, definition is map, isCreating is boolean, specifiedParameters is map, hiddenBodies is Query) returns map { definition.showDia1=false; definition.showDia2 =false; println(definition.sizeTable.dia3); if(definition.sizeTable.dia3 =="25") { definition.showDia1=true; definition.showDia2 =true; } return definition; }You will need editing logic for this to work.
0 -
Jacob, thanks a lot for your comment!. This works but I am trying to create a logic that would make the max value in lengthbound of dia2 < the selected dia3, and the max value in lengthbound of dia1<dia2. Do you think this is possible?Jacob_Corder said:FeatureScript 2144; import(path : "onshape/std/common.fs", version : "2144.0"); export const sizeTable = { "name" : "dia3", "displayName" : "Dia3", "default" : "25", "entries" : { "25" : { "name" : "StockHeight", "displayName" : "StockHeight", "default" : "140", "entries" : { "60" : 60 * millimeter, "100" : 100 * millimeter, "127" : 127 * millimeter, "140" : 140 * millimeter } }, "20" : { "name" : "StockHeight", "displayName" : "StockHeight", "default" : "125", "entries" : { "60" : 60 * millimeter, "84" : 84 * millimeter, "104" : 104 * millimeter, "125" : 125 * millimeter } } } }; annotation { "Feature Type Name" : "Tool4","Editing Logic Function":"tool4EditLogic" } export const tool4 = defineFeature(function(context is Context, id is Id, definition is map) precondition { annotation { "Name" : "showDia1","UIHint":UIHint.ALWAYS_HIDDEN } definition.showDia1 is boolean; annotation { "Name" : "showDia2","UIHint":UIHint.ALWAYS_HIDDEN } definition.showDia2 is boolean; annotation { "Name" : "Tool height", "Lookup Table" : sizeTable } definition.sizeTable is LookupTablePath; if (definition.showDia1 ) { annotation { "Name" : "Dia1" } isLength(definition.dia1, { (millimeter) : [1, 14, 14] } as LengthBoundSpec); } if(definition.showDia2) { annotation { "Name" : "Dia2" } isLength(definition.dia2, { (millimeter) : [14, 16, 19] } as LengthBoundSpec); } annotation { "Name" : "height1" } isLength(definition.height1, { (millimeter) : [1, 20, 100] } as LengthBoundSpec); annotation { "Name" : "height2" } isLength(definition.height2, { (millimeter) : [1, 20, 100] } as LengthBoundSpec); } { }); export function tool4EditLogic(context is Context, id is Id, oldDefinition is map, definition is map, isCreating is boolean, specifiedParameters is map, hiddenBodies is Query) returns map { definition.showDia1=false; definition.showDia2 =false; println(definition.sizeTable.dia3); if(definition.sizeTable.dia3 =="25") { definition.showDia1=true; definition.showDia2 =true; } return definition; }You will need editing logic for this to work.
0 -
@User1_Livetools
You can only over ride a users input in edit logic so if someone types in a value too big or small, you just modify it to the min value if too small or the max value if too big. Just set it in the edit logic function that I provided above0
