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.
Nesting ternary operators?
Henk_de_Vlaam
Member, Developers Posts: 242 ✭✭✭
Is it possible to nest ternary operators in a variable definition?
I tried this: #D<301mm?3:#D<451mm?4:#D<501mm?5:#D<601mm?6:6. However it gives an error.
Is there another way?
Henk de Vlaam (NL)
0
Best Answer
-
ilya_baran Onshape Employees, Developers, HDM Posts: 1,215I think it should work, though I would recommend parentheses. Can't tell what's actually wrong without a public doc link.
Even better though, I'd recommend writing a function in a feature studio for this, so you can use if statements, etc. See my comment here: https://forum.onshape.com/discussion/comment/18476#Comment_18476
The custom function could be pretty generic, taking a map as an input, working like:
#rangeValue(#D, { 301mm : 3, 451mm : 4, 501mm : 5, 601mm : 6 }, 6)
Post if you need help writing this.Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc5
Answers
https://cad.onshape.com/documents/f050e58e3939d5ddfe8074cd/w/7e67687934f04f4780fc4590/e/c543bd2493c92929656cd6ba
Can you share a document where the error is occurring?
Even better though, I'd recommend writing a function in a feature studio for this, so you can use if statements, etc. See my comment here: https://forum.onshape.com/discussion/comment/18476#Comment_18476
The custom function could be pretty generic, taking a map as an input, working like:
#rangeValue(#D, { 301mm : 3, 451mm : 4, 501mm : 5, 601mm : 6 }, 6)
Post if you need help writing this.
I extracted the features that give the error in a new part studio:
https://cad.onshape.com/documents/f74debfb833b8135e5c28259/w/ab516eb7d8c390bb970f1a59/e/43762454ad2feecb458085a8
The ternary operator is driven by the configuration variable Dia onder.
The part that comes to you is without error. However when you replace the number 401 by the wished value 451 in the variable #Spaken there will be an error. Also when inserting the intended #D_onder<301mm?3:#D_onder<451mm?4:#D_onder<601mm?5:6 the error remains.
--- Edit [20180930] ---
I changed the model and now the value 451 is excepted. However the full ternary range still gives an error.
Is it possible that the use of a configuration variable is the reason of this error?
Is there an answer for the September 29 topic?
The problem has been solved by using parentheses.
@ilya_baran, you mentioned already the parentheses, but I did not know how to use them. The contribution of @brian_brady in topic https://forum.onshape.com/discussion/7128/a-few-expression-tips brought me to the solution.
So, I changed #D_onder<301mm?3:#D_onder<451mm?4:#D_onder<601mm?5:6
to
#D_onder<301mm?3:(#D_onder<451mm?4:(#D_onder<601mm?5:6)).
@kevin_o_toole_1, your solution to add the ternary operation directly to the pattern "Instance count" also works, but with me only with the parentheses (see "Circular pattern OK" of https://cad.onshape.com/documents/f74debfb833b8135e5c28259/w/00f467661c0e8c373c355f2a/e/43762454ad2feecb458085a8).
Thank you all.