Functions and operators
The following functions and operators can be used in rules. This means that they are recognized by the rule parser and will be handled by the system. Not all functions are relevant in all situations.
Functions
The following functions can be used in the rule system.
Standard functions
abs, sin, cos, tan, sinh, cosh, tanh, ln, log, log10, log2, exp, sqrt, pow
Unlimited number of arguments
min, max, sum
String functions
-
str2dbl – Converts a string to float value.
-
strlen – Returns the string length.
-
tolower – Converts lowercase letter to uppercase.
-
toupper – Converts uppercase letter to lowercase.
Complex functions
-
real – Returns a value as real a number.
-
imag – Returns imaginary part of the complex number.
-
conj – Returns the conjugate of the complex number.
-
arg – Returns the argument of the complex number.
-
norm – Returns the norm value of a complex number.
Array functions
-
sizeof – Returns the size of the expression (the number of elements in the array).
-
eye – Creates a matrix with ones in the main diagonal and zeros everywhere else.
-
ones – Creates a new m x n matrix filled with ones.
-
zeros – Creates a new m x n matrix filled with zeros.
Special functions
-
RGB – For generating a color. Encodes red (r), green (g) and blue (b) components into an integer value representing a color. The values are in the range 0…255.
int rgb(int r,int g,int b)
For example, RGB(255,0,0) returns bright red. RGB(255,255,0) returns yellow.
-
minval and maxval – For determining the minimum and maximum value of a logistical field for the active block.
float minval(char field), float maxval(char field)
Considers the specified field for all present parts in the block and returns the smallest or largest value. The type of the field can be numerical or string.
In case of a string value, considers all available values for the field and orders them alphabetically (duplicate values are removed). For string values, the value returned by minval is the index of the first value (always 0), and the value returned by maxval is the index of the last value (always the amount of unique values minus 1).
-
strval – For converting a character value of a logistical field to a numerical value. If the specified field defines a string value, the returned value is the index of the value in the list.
float strval(char field,char value)
-
strcmp – For comparing two strings, case sensitive *
strcmp(const char *str1, const char *str2)
-
stricmp – For comparing two strings, case insensitive *
strcmp(const char *str1, const char *str2)
-
rainbow – Returns a rainbow of colors corresponding to value clamped by min (red) and max (blue), using the defined number of colors. This means that the system maps the specified minimum value to red and the specified maximum value to blue.
int rainbow(float min,float max,float value,number of colors)
The value to determine the color for should be somewhere between the minimum and maximum value (i.e. between red and blue). The corresponding color is returned. If the specified value is smaller than the minimum or larger than the maximum, 0 (black) is returned
-
inv_rainbow – Returns an inverse rainbow of colors corresponding to value clamped by min (blue) and max (red), using the defined number of colors.
int inv_rainbow(float min,float max,float value,number of colors)
-
frame_d – Returns the decimal frame number corresponding to the specified length.
float frame_d(float length)
-
string frame_o(float length) – Returns the frame number and offset corresponding to the specified length.
string frame_o(float length)
-
wldcmp – For comparing strings using wildcards. Returns a boolean value true if the arguments match, and false if they do not match. The first argument is the variable to search in, and the second argument is the search string in double quotes. Wildcards * and ? can be used in the search string before and after actual characters. Examples:
-
wldcmp(Processingname,"*-S*") $ "1"
-
wldcmp(Processingname,"?-S*") $ "1"
-
wldcmp(Processingname,"?-S?") $ "1"
-
* Note that strcmp and stricmp are general string comparison functions. You can use them to compare for example a part's panel code to a specific panel code: (strcmp(panel_1,”AA”)==0 …)
Other functions
-
print – Used to send specific strings or values to the standard output. The number of parameters is not fixed.
-
substr – A function for extracting a continuous set characters from a string. The function takes 2 or 3 parameters:
-
the 1st parameter is the string from which the characters are to be extracted.
-
The 2nd parameter is the position of the first character to be extracted from the string.
-
The 3rd parameter is the position of the last character to be extracted from the string.
If the 3rd parameter is omitted, all the characters starting from the position defined in the 2nd parameter up to the end of the string are extracted.
-
Example 1:
s1=”ABCDEF”
s2=substr(s1,1,3)
print(“s2 = “,s2)
Result: s2 = ABC
Example 2:
s2=substr(s1,-3,-1)
print(“s2 = “,s2)
Result: s2 = DEF
Example 3:
s2=substr(s1,3,4)
print(“s2 = “,s2)
Result: s2 = CD
Example 4:
s2=substr(s1,5)
print(“s2 = “,s2)
Result: s2 = EF
Example 5:
s2=substr(s1,-2)
print(“s2 = “,s2)
Result: s2 = EF
Operators
The following operators can be used in the rule system.
-
Standard operators
+, -, *, ^
-
Logical operators
and, or, xor, ==, !=, >, <, >=
-
String concatenation
//
-
Conditional if–then–else operator with lazy evaluation
?:
Example: a=b<c ? b : c will set a to b if b is smaller than c, otherwise a will be set to c.