Working with complex formulas

Working with complex formulas

Working with complex formulas

In this article we will look at working with formulas in the Valentina pattern making software. From simple cases to complex ones.

Numerical values

A formula can only consist of one numeric value. Both negative and positive numbers and zero are allowed. Particular attention must be paid to fractional numbers. The fractional part can be separated by either a comma or a dot. This is influenced by the settings of your operating system, as well as by the settings of the program itself.

If a formula requires a value greater than zero, and you want it to be zero, you can write something very close to zero as the value. For example, 0.0001. Technically, this would be the same, as the accuracy value is programmatically set. Right now it is 0.155mm. In other words, if the distance between the points is less than the boundary value, these points will be considered the same.

Mathematical operations

More complex formulas use the mathematical operations of addition (+), subtraction (-), multiplication (*), division (/), and exponentiation (^). Here, it’s worth remembering to prioritize operations.

In some cases, Valentina allows interactive interaction with drawing objects. For example, you can change the shape of a curve in this way. This is only possible if the formula is a simple numeric value. In this case, the value is overwritten with the new value. If you want to disable overwriting, but want to keep the numerical value, you can add an edit that will not affect the value, but will make the formula more complex. For example, you could add + 0, or * 1.

Change the priority

Use the familiar parentheses ‘(’, ‘)’ to change the precedence.


Variables are named values. When such a value is substituted into a formula, the program will automatically replace it with the corresponding value and do the calculation. This makes the expression more readable and portable.

Valentina supports several types of variables:

  • Measures. In current versions of the program, there are currently two types of measures: custom measures and known measures. Custom measures must necessarily have a @ symbol in front of the name. The user himself makes up the name of the measure. The names for known measures are taken from known measure database and their name cannot be changed. The measurements are stored in a separate file and are connected to the pattern file. It is not mandatory to have a measurement file attached, so the measurement list can also be empty.
  • Increments. Increments are similar to measures, but are saved in the pattern file. They are logically divided into two categories: increments and preview calculations. Each category name starts with symbol #.
  • Object parameters. This group includes line lengths, line angles, curve lengths, arc angles, arc radiuses, etc. Valentina automatically creates these variables for you.

When working with formulas, remember the order in which the objects are created.

Local variables

In the previous section, we described global variables. But sometimes, we want to save the result of an intermediate calculation and use it later. This is achieved by using local variables. To do this, start the name of a variable with #, put an equal sign after the name and write the expression. At the end put a semicolon. Moving to a new line, start a new expression. In it, you can use the local variable described earlier. The last line does not require a semicolon character. In practice, it will look like this.

#a = 5 + 3;
#a * 2 + #a * 5

As a result, the program will return 56.

Care must be taken when working with local variables. The behavior of the program has changed in the test version. If you use a variable in an expression that has not been previously assigned a value, then the program will assign it a special designated nan (not a numeric value) instead of 0. Any operation on such a number turns the expression into nan, which makes the value of the formula invalid. This helps you quickly determine that there is an error in the formula, as opposed to 0 which would mask the fact.


A function is a named operation that evaluates arguments and returns the result. Valentina maintains a list of built-in functions that you can use for your calculations. Each function has a name and a list of arguments. The list of arguments is written in brackets immediately after the name and is separated by a semicolon.

Conditional statement

Formulas using a conditional operator are even more complex. Thus far we have only dealt with linear expressions. With a conditional operator, it is possible to get a result depending on the fulfillment of the conditions. It has the form: <condition> ? <true> : <false>. If the condition is true, then result from the branch true. If not, then result from the branch false. In practice, it might look something like this.

#a = 5 + 3;
#a > 9 ? 24 : 0

If #a is more than 9, then the result of the formula is 24, otherwise 0. In our case the answer is 0, 8 is less than 9.

Cases where one ternary operator is nested in another are also allowed. For example:

#a = 5 + 3;
#a > 9 ? 24 : #а > 3 ? 4 : 0

This concludes our overview of working with formulas in the Valentina pattern making software. You can learn even more about the features of the program from our paid materials: books and video courses.


  • rass5000

    rass5000 User


    Спасибо! интересное почерпнул.


Post your comment