You can use expressions in any numeric feature in Onshape, including features, dimensions, variables, and even configuration tables. Expressions evaluate using FeatureScript and the result must contain no units or units to the first power (such as length, but not area or volume).
Most mathematical functions are allowed in expressions. These include operators such as exponent (^), multiplication (*), division (/), addition (+), and subtraction (-). They also include more complex functions such as ceil, floor, round, exp, sqrt, abs, max, min, and log. A full list of functions are listed in the Standard Library Documentation under math.
To add more flexibility, conditional statements are also allowed. One way to do this is an array with a lookup value as shown below:
The position requests the value at position 3. The result is 8 because the position count starts at 0.
In a practical example for a pipe flange, the position is denoted by the class of flange. A 300# flange sets the #Class variable to 1.
The #Class variable is then used to determine the dimensions based on the Nominal Pipe Size and an array.
Another form of conditional statement uses a ternary operator (similar to an IF statement). This uses a condition, Value if True, and Value if False, as shown below:
In this example, if the number of USB ports chosen for a configuration is greater than 3, it will evaluate to 3. Otherwise, it will evaluate to 2. After plugging the formula into the instance count for computer fans, you can see that the number of fans updates appropriately.
Expressions are a powerful tool in Onshape that can cut down on configured features and add more automation to your design variants.
Interested in learning more Onshape Tech Tips? You can review the most recent technical blogs here.