</p>
How to getAllVariables() in defineFeature.precondition?
In a defineFeature, I would like to list all variables in the precondition. Here is my code:
FeatureScript 2559;
import(path : "onshape/std/common.fs", version : "2559.0");
annotation { "Feature Type Name" : "Set Variable", "Feature Type Description" : "" }
export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
precondition{
for (var key, value in getAllVariables(context)) { …
However, the getAllVariables() function throws an error: "Expected iterated container to be defined as a field on definition."
My goal is to create a dropdown list containing all the variables and allow the user to select one.
How could I achieve this? Thanks for your attention!
Best Answer
-
This isn't presently supported - a dropdown is an enum parameter, and all options must be known when you're writing the feature. Meanwhile, variables are only known after you regenerate the Part Studio.
What are you trying to do? Can you use a quantity parameter (like length/angle/isAnything)?
0
Answers
-
This isn't presently supported - a dropdown is an enum parameter, and all options must be known when you're writing the feature. Meanwhile, variables are only known after you regenerate the Part Studio.
What are you trying to do? Can you use a quantity parameter (like length/angle/isAnything)?
0 -
Thank you, @_anton, for your answer.
I understand the limitation with dropdown enums.
My goal was to write a custom feature where the user could choose a variable from a dropdown list.
Since this is not feasible at the moment, I will use a text input field where the user will write the name of the variable.
0

