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. |
expression1 + expression2 |
|
expression1 - expression2 |
|
|
expression1 * expression2 |
|
|
expression1 / expression2 |
|
|
Logical Note: The logical operators will only work with boolean expressions. |
expression1 & expression2 |
| (OR)The expression1 | expression2 |
|
| Relational |
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. |
|
expression1 <> expression2 |
|
< (Less than)The expression1 < expression2 Note: The |
|
> (Greater than)The expression1 > expression2 Note: The |
|
|
expression1 <= expression2 Note: The |
|
|
expression1 => expression2 Note: The |
|
| Assignment |
The example below defines an expression and assigns it to a temporary field named 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 |
result = expression1 ^ exponent Note: The |
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