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.
Why doesn't this work?
Dylan_Stewart
Member, Developers Posts: 107 PRO
Hello all, I have a seemingly quick question. I am playing around with arrays and have come across a problem when trying to append under a conditional statement.
I'm not sure why my code works with the boolean in the precondition but doesn't when I take it out and try to use the (definition.selection == selection.K) if fails....????
I'm not sure why my code works with the boolean in the precondition but doesn't when I take it out and try to use the (definition.selection == selection.K) if fails....????
FeatureScript 686;
import(path : "onshape/std/geometry.fs", version : "686.0");
export enum selection
{
annotation { "Name" : "1" }
A,
annotation { "Name" : "2" }
B,
annotation { "Name" : "3" }
C,
annotation { "Name" : "4" }
D,
annotation { "Name" : "5" }
E,
annotation { "Name" : "6" }
F,
annotation { "Name" : "7" }
G,
annotation { "Name" : "8" }
H,
annotation { "Name" : "9" }
I,
annotation { "Name" : "10" }
J,
annotation { "Name" : "Custom" }
K
}
function selectionID(value is selection)
{
return {
"A" : 0,
"B" : 1,
"C" : 2,
"D" : 3,
"E" : 4,
"F" : 5,
"G" : 6,
"H" : 7,
"I" : 8,
"J" : 9,
"K" : 10
}[value as string];
}
annotation { "Feature Type Name" : "My Feature" }
export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
annotation { "Name" : "Selection" }
definition.selection is selection;
if (definition.selection == selection.K)
{
annotation { "Name" : "My Count" }
isInteger(definition.myCount, POSITIVE_COUNT_BOUNDS);
annotation { "Name" : "My Boolean" }
definition.myBoolean is boolean;
}
}
{
var selection = selectionID(definition.selection);
var myArray = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100];
// if (definition.selection == selection.K)
if(definition.myBoolean)
{
myArray = append(myArray, definition.myCount);
}
var sketch1 = newSketch(context, id + "sketch1", {
"sketchPlane" : qCreatedBy(makeId("Front"), EntityType.FACE)
});
skLineSegment(sketch1, "line1", {
"start" : vector(0, 0) * inch,
"end" : vector(0, myArray[selection]) * inch
});
skSolve(sketch1);
});Digital Engineering
0
Best Answer
-
jon_sorrells
Onshape Employees Posts: 52
You have a local variable with the same name as your enum: selection.
I suggest naming the enum Selection.
5
Answers
I suggest naming the enum Selection.
It's the little things... Thank you so much @jon_sorrells