Common Maths Scripting Rules

While Evolution scripting varies depending on context, there are some common rules that apply to all scripts.

Reading and writing attributes

Lets look at the following script:

new_attribute = 10

If you run the script above, an attribute called new_attribute will be created per block or solid in the model you are referring to, and the attribute will be set to the integer (10).

Similarly, you can create a string attribute as follows:

new_attribute = "10"

You can also create attributes by reading existing data using the block and solid keywords, as follows:

new_attribute = block.block_tonnes

In the above example, we access an existing attribute called block_tonnes from the block model using the block. notation and assign it to a new attribute called new_attribute. This means that every block in the block model will have an attribute called new_attribute with a value equal to the attribute block_tonnes. You can apply a similar script for solid models.

If you only want to create an attribute to refer to within your script for clarity purposes, you can wrap the definition inside a define statement, as follows:

new_attribute = define(block.block_tonnes)

This means that new_attribute only exists inside your script and it will not be added to the block model. The same concept applies to solid models when using the solid keyword.

Numerical operators

Operators are symbols used to define the operations performed within an expression. In report formulas, these operators are grouped into distinct categories, as outlined in the table below.

Category Operators

Arithmetic

Note:  The arithmetic operators will only work with numeric expressions.

+ (Addition)
The + operator computes the sum of its two operands, as follows:

expression1 + expression2

-(Subtraction)
The - operator subtracts the value of the second operand from the first, as follows:

expression1 - expression2

* (Multiplication)
The * operator computes the product of its two operands, as follows:

expression1 * expression2

/ (Division)
The / operator divides its first operand by its second operand, as follows:

expression1 / expression2

Logical

Note:  The logical operators will only work with boolean expressions.

& (AND)
The & operator performs a logical AND between its operands, returning true only if both evaluate to true; otherwise, it returns false, according to the following format:

expression1 & expression2

| (OR)

The | operator performs a logical OR between its operands, returning false if both evaluate to false; otherwise, it returns true, according to the following format:

expression1 | expression2

Relational

=(Equality)
The = operator returns true if the values of each of its operands are equal; otherwise, it returns false, according to the following format:

expression1 = expression2

Note
The = operator should not be confused with the assignment operator. The symbol itself is the same; the difference is the context in which it is used. For example, in the filter = define(block.Stage = "one") script, the first = symbol is an assignment operator. The second = symbol is an equality operator indicating that the stage is equal to one.

<> (Inequality)
The <> operator returns false if both its operands are equal; otherwise, it returns true, according to the following format:

expression1 <> expression2

< (Less than)

The < operator returns true if the first operand is less than the second; otherwise, it returns false, according to the following format:

expression1 < expression2

Note:  The < operator will only work with numeric expressions.

> (Greater than)

The > operator returns true if the first operand is greater than the second; otherwise, it returns false, according to the following format:

expression1 > expression2

Note:  The > operator will only work with numeric expressions.

<= (Less than or equal)
The <= operator returns true if the first operand is less than OR equal to the second; otherwise, it returns false, according to the following format:

expression1 <= expression2

Note:  The <= operator will only work with numeric expressions.

>= (Greater than or equal)
The >= operator returns true if the first operand is greater than OR equal to the second; otherwise, it returns false, according to the following format:

expression1 => expression2

Note:  The => operator will only work with numeric expressions.

Assignment

= (Assignment)
The = operator takes the expression on its right and assigns it to the field on its left. You can use it to create definitions and to specify output columns.

The example below defines an expression and assigns it to a temporary field named myfilter:

myfilter = define(block.CenX > 1)

In the example below, the value of the expression on the right is output as a column in the report:

mycolumn = sum(block.CenX)
Power

^ (Power)
The ^ operator raises a number to the power of another number, according to the following format:

result = expression1 ^ exponent

Note:  The ^ operator will only work with numeric expressions.

String manipulation

You can create strings in all Evolution scripts using concatenation. Concatenation is where you add strings together to create a new string, as shown in the example below:

new_attribute_concat = "str" + "str2"
// new_attribute_concat = "strstr2"

You can check if a string attribute contains another string by using the keyword contains. The expression will return a boolean value. Therefore, expressions that use the contains keyword can only be used for filters. If you need to use contains in a maths script, you need to use the keyword within an if function, as follows: 

new_attribute_string = define("10")
new_attribute_contains = if(new_attribute_string contains "1", 10, 4)
// new_attribute_contains = 10