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 few expression tips.
lougallo
Member, Moderator, Onshape Employees, Developers, csevp Posts: 2,004
Over the last couple of months we have received a number of questions on how to make expressions in the Onshape dimension and feature dialogs and I wanted to share a few of them with you all. You can read about most of them in our help documentation here: Numeric fields
As illustrated in our help you can do most math functions:
I thought this might be useful and I will try to get some examples added to our help as well. ~Lou
As illustrated in our help you can do most math functions:
</code>+, -, *, /, ^, ceil, floor, round, exp, sqrt, abs, max, min, log, log10</pre>A few examples:<br><pre class="CodeBlock"><code>ceil(5.667) = 6 floor(5.667) = 5but we also support a array/lookup table like this: (remember the array starts at 0) . (Array example)
[3,5,6,7][2] = 6 [3,5,6,7][3] = 7and ternary operators which can yield conditional results. For example let's say I want the #length of my rectangle to be 7in if the width is > 5in, otherwise make it 4in. (Ternary example)
#width>5?7:4Note: In the example file I am also making the hole fail if the #width is less than 4in.
I thought this might be useful and I will try to get some examples added to our help as well. ~Lou
Lou Gallo / PD/UX - Support - Community / Onshape, Inc.
Tagged:
13
Comments
Awesome
Eduardo Magdalena C2i Change 2 improve ☑ ¿Por qué no organizamos una reunión online?
Partner de PTC - Onshape Averigua a quién conocemos en común
Cheers, Owen S.
HWM-Water Ltd
This example sets the value to 1 if width is less than 4, 2 if equal to 4, and 3 if greater than 4
Twitter: @onshapetricks & @babart1977
https://cad.onshape.com/documents/d84339a898f6048107f919e7/w/6bf19a60af5f77fc35b79e73/e/c14681bd9486c363d1cd88a6
Fail means the browser will turn red and will have error msg that it didnt regenerate properly?
Is it okay if we just leave it red?Just a question?
Nested conditional statements are cool! Thanks @lougallo and @brian_brady for the tips.
Thanks Jake.
Owen S.
HWM-Water Ltd
HWM-Water Ltd
HWM-Water Ltd
Unless I enter the units...
So, 10mm*2 = 20mm. Using dimensional analysis, onshape knows that the result should have a length unit.
However, 10mm - 2 does not work because onshape doesn't make assumptions and doesn't know what the units for the result should be. Is it 2 inches? 2 feet? 2mm?
This is magic, thanks