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.
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
-
_anton Member, Onshape Employees Posts: 421
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)?
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.