Skip to main content

Expressions

Introduction#

It is possible to use expressions in interactive design environment of buerligons but also in the Headless (history API) programming. Expressions help us to define properties of cad objects like features, sketches, working geometry, ... by using mathematical expressions. Each expression contains a name and a mathematical expression.

to define an expression. In buerligons you can open the expression plugin by clicking on the following button:

drawing

Button to open expressions plugin in buerligons

Defining expressions makes sense if you want to make dependencies between properties or configure variants of the same model. Accessing expression and change them is possible with history API and of coursce interactively in buerligons. Updating an expression means that the whole model needs to be recalculated. A simple expression can have a deep impact to the whole model and many of its features.

Plugin#

Let's have a look into the expression plugin in buerligons.

drawing

Expressions plugin in buerligons

As you can see, we've only created three expressions for height, length and width. Each expression has been set to 100. So it's not a complex mathematical expression, there are only simple values. To connect them to the dimension of the box, we need to open the box feature.

drawing

Plugin of box feature

Connecting a value / property to an expression can be done with the small button next to the value field. We can change between "v" for value and "e" for expression. As soon as we switch to "e" a dropdown will pop up and let us chose an existing expression. In the picture above we can see that we've already set the expression for height and width, but not for length. After updating the box feature, we are able to change the values of any expression in the expression plugin and the box will automatically change its size.

For expressions which are not used in multiple features, we can define the expression directly in the input field. We don't need to do that via expression plugin. Just switch from "v" to "e" and write the expression into it.

drawing

Define expressions directly in input fields of plugins

📝 Note: When working with angles, whether with or without expressions, the values are assumed to be angles in radians. To work with angles in degrees, one can simply add a "g" after the value.

In the following snippet you can see how to use angles in different ways. Using the "g" after a value will convert the value into radians in the background. You can use the "g" for simple value inputs, but also for expressions.

drawing

Working with angles in different ways

Mathematical expression#

In the chapter before we simply added three expressions with a real value. That's fine but actually we can do much more with expressions. Let's think about a box where the height of the box is always double the its width. The width will still be a simple value, which we can change to any value. The height on the otherside will need a mathematical expression. Let's see how to do that:

drawing

height of the box with mathematical expression

In the input field of the expressions we can access the value of other expressions by just using their names. As you will see in the gray and disabled input field next to the mathematical expression, the expression will always be solved to see what the actual value is after solving the mathematical expression.

Here's a list with all possible mathematical functions and constants you can use in the input field.

functiondescription
abs(value)returns the value without sign.
sign(value)returns the sign of the value (+1 or -1). 0 returns 0.
max(value1, ..., valuen)returns the biggest value of the arguments.
min(value1, ..., valuen)returns the smallest value of the arguments.
a_r(value)converts an angle from degree to radian.
r_a(value)converts an angle from radians to degree.
sin(value)sin of value (rad) is returned.
sinh(value)sinh of value (rad) is returned.
asin(value)arcsin of value (rad) is returned.
cos(value)cos of value (rad) is returned.
cosh(value)cosh of value (rad) is returned.
acos(value)arccos of value (rad) is returned.
tan(value)tan of value (rad) is returned.
tanh(value)tanh of value (rad) is returned.
atan(value)arctan of value (rad) is returned. Or arctan(value/Divisor) is returned. The second version gives values in the range of {-PI,PI}
exp(value)exp of value is returned.
ln(value)ln of value is returned.
log(value)log of value is returned.
sqrt(value)square root of value is returned.
pow(value, exponent)value is raised to the Exponent power.
fmod(value1, value2)res = value1 Modulo value2 (remainder of value/value2)
div(value1, value2)res = (int)(value1 / value2 (DIV operator for integer)
C:PIdefinition for PI. (3.14159265358979323846)