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 add an unlimited number of predecates
EvanReese
Member, Mentor Posts: 2,144 ✭✭✭✭✭
I'm wanting to create a Multi-Variable feature that allows for several variable declarations at once. I'm trying to figure out the best way to structure the UI for that. Ideally, the user should be able to click a button to add another variable, or (less preferably) to be able to use a count parameter at the top to say how many there should be. Here's what I've got so far, but the code seems clumsy. I'm just nesting if statements for each additional variable input, so there's a limit on how many variables someone could declare. Who knows, maybe I could just limit it to 5 and that's a good thing so the dialog window doesn't go off-screen. Thoughts?
Evan Reese
0
Best Answer
-
kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565Fill has an array parameter with a "driven query". You want a normal array parameter.
See https://cad.onshape.com/FsDoc/uispec.html#arrays5
Answers
See https://cad.onshape.com/FsDoc/uispec.html#arrays
@kevin_o_toole_1 That seems like exactly what I'm looking for. I'm out of time to test it right now, but I'll report back once I do.
if (definition.type == Type.A)
) but can't depend on individual array items (likeif (profile.type == Type.A)
).You can vote on the improvement request to support the latter here: https://forum.onshape.com/discussion/7628/conditional-visibility-of-array-parameters/p1
Here's the link.
I expected this to work as long as #nominal is declared before #rib, since the for loop is iterating through, and by the time it's on the second iteration #nominal has already been declared. It doesn't seem to work that way, which limits the usefulness of the feature, at least for the way I work. Any pointers on how to get this working? Can it even be done?
It most likely will not be able to be done because Onshape actually works out the values before the feature even starts, so that is why you cannot reference a variable created in the feature.
IR for AS/NZS 1100
I think I see what you're saying. It loops through the whole predicate before it even starts executing the feature, so there's no way the values computed by the feature can feed back into the predicate. If they could, I could write recursive nonsense. Something like that?
Before I give up on it completely, does anyone else have any tricks for something like this? I wonder if there might be a way to parse the values in the execution part of the code. I know getVariable() can reference an existing variable within one feature. I've started a new thread here since this seemed like a new topic.
All I really want for Chirstmas is:
IR for AS/NZS 1100
not sure what I'm looking at here, but it seems like you're showing it working. If I enter the same values I'm getting an error. Care to expound a bit?
How about this:
IR for AS/NZS 1100
Here is the link:
http://onsha.pe/documents/da7abfbf7607534743ef3e77
Here is what I am doing:
In the UI, the value parameters are strings, rather than using isAnything.
The FeatureScript then passes those values to a little library that I made, which evaluates the value of the string, checking if it needs to use another variable and calculating the other variable if so (Circular references are also checked).
Those values are then set for each variable and populated into the Variable summary notification
IR for AS/NZS 1100
I'm so far from being able to write something like that. I'll dig into how you did it after hours sometimes and I'm sure I'll learn a lot. Thank you for taking the time. I'll probably be back with questions once I've sat with it a while.
Here is the library that I am using:
http://onsha.pe/documents/429fd7dda5f0fdb93833a34a
It exports a function called evalExpression that takes a string and a map of variables.
This function first splits the text into tokens. e.g: "5 + 5" => [5, "+", 5]
It then checks for any variables that it needs that have not been calculated. If there is any needed variables, it returns an array of variable names that it needs.
After this, it converts the tokens to Reverse Polish Notation (RPN). e.g: [5, "+", 5] => [5, 5, "+"]
After it has been converted to RPN, it then evaluates the RPN and returns the end value.
IR for AS/NZS 1100
Nice!
Would there be any way to get autocomplete for the functions and variables to work with this, or would it have to be supported internally?
IR for AS/NZS 1100
Hopefully, they could be set up as globals for the whole doc, and maybe even linked between documents the same way parts are.