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.
A little more on configuration.
brian_pinder662
Member Posts: 119 ✭✭
I am trying to enter the following variable into a dimension box #PipeRad21mm ? 105mm : 99.8066mm What I am trying to say is (If the PipeRad is 21mm then this dimension is 105mm otherwise it is 99.8066mm)
but the the dimension box will not accept this saying please enter a valid expression
Could anyone please say where i am going wrong
Any help will help me to move on. Best Regards Brian.
but the the dimension box will not accept this saying please enter a valid expression
Could anyone please say where i am going wrong
Any help will help me to move on. Best Regards Brian.
0
Best Answers
-
john_mcclary Member, Developers Posts: 3,938 PROyou have to use the "==" operator between your variable and first dimension
#PipeRad == 21 mm ? 105 mm : 99.8066 mm
5 -
john_mcclary Member, Developers Posts: 3,938 PROWhat part isn't sinking in? the format of the inline If statement?
variable = (something is true) ? (then do this) : (otherwise it is false so do this)
anything before the ? is a test condition, which is comparing two objects at a time using comparison operators
x > y is greater then
x < y is less than
x >= y is greater than or equal to
x <= y is less than or equal to
x == y is equal to
x != y is not equal to
x && y compares two booleans, result must be true example: (1 <= 2 && 3 < 4) = true
x || y compares two booleans, result will be true if ether x, y, or both are true
then there are some more commands you will need find on the featurescript documentation like Ilya showed
tolerantEquals(x, y)
the format above is a common short hand version of an If-else statement
If (boolean is true)
{ then do this }
else
{ otherwise do this }
you can nest multiple statements together to hone in on a specific result.
an easier way to read it would be to write it out like a normal If statement in notepad, then shrink it into one line
example:x > y ? z<br>: x == y ? a<br>: b<br><br>becomes:<br>x > y ? z : x == y ? a : b<br><br>if x > y then the result of the equation will be z<br>if x = y then the result of the equation will be a<br>if all else fails then the result of the equation will be b<br><br>You can also use ( ) as much as you need to help visualize your groups<br>(x > y)? z :(x == y)? a :b
Hope that helps, not make things worse6
Answers
#PipeRad == 21 mm ? 105 mm : 99.8066 mm
tolerantEquals(#PipeRad, 21 mm) ? 105 mm : 99.8066 mm
and unlike == it'll be robust to rounding errors if #PipeRad is computed in any way other than evaluating the expression "21 mm"
variable = (something is true) ? (then do this) : (otherwise it is false so do this)
anything before the ? is a test condition, which is comparing two objects at a time using comparison operators
x > y is greater then
x < y is less than
x >= y is greater than or equal to
x <= y is less than or equal to
x == y is equal to
x != y is not equal to
x && y compares two booleans, result must be true example: (1 <= 2 && 3 < 4) = true
x || y compares two booleans, result will be true if ether x, y, or both are true
then there are some more commands you will need find on the featurescript documentation like Ilya showed
tolerantEquals(x, y)
the format above is a common short hand version of an If-else statement
If (boolean is true)
{ then do this }
else
{ otherwise do this }
you can nest multiple statements together to hone in on a specific result.
an easier way to read it would be to write it out like a normal If statement in notepad, then shrink it into one line
example:
x > y ? z<br>: x == y ? a<br>: b<br><br>becomes:<br>x > y ? z : x == y ? a : b<br><br>if x > y then the result of the equation will be z<br>if x = y then the result of the equation will be a<br>if all else fails then the result of the equation will be b<br><br>You can also use ( ) as much as you need to help visualize your groups<br>(x > y)? z :(x == y)? a :b
Hope that helps, not make things worse
all the best Brian.