Skip to main content

Expressions

On this page you will find explanations about how to use expressions in the headless environment. Expressions in general are already described on this page here.

Within the history API we're able to create, update and delete expressions.

Depending on how we're going to create our models we use this methods more or less. For example if we create the whole model by code we need to create the expressions first and update them later. In case of the model has been created with our interactive CAD application called buerligons, we've probably created the expressions already and only need to update them to configure the model.

To create expressions you can call:

// Create expressions
api.createExpressions(part,
{ name: 'width', value: 50 },
{ name: 'length', value: 80 },
{ name: 'height', value: '2 * width'},
{ name: 'angle1', value: '360g / holeCount' }, // using degrees in expression
{ name: 'angle2', value: 'C:PI * 2 / holeCount' }, // using radians in expression
)

After creating the expressions they will be found in the expression set. It's possible to use them directly in the code for further operations. You can access them by "ExpressionSet.[name of the expression]". Let's create a box by code and connect its members / properties with the created expressions to see how it works:

// Creating a box and connect expressions
const box = api.box(part, [], 'ExpressionSet.width', 'ExpressionSet.length', 'ExpressionSet.height')

Often we create the model interactively and also set all expressions in buerligons. In that case we don't need to create, but can directly access them by code using the setExpressions() method. To change the expressions we've created above we can simply call:

// Update expressions
api.setExpressions({
partId: part,
members: [
{ name: 'width', value: 60 },
{ name: 'length', value: 70 },
{ name: 'height', value: '3 * width' }
],
})