Expression
Expressions determining the values of the variables can contain operands (real constants and variables, text constants and variables) and operations (a set of actions upon these variables). Expressions can also include functions.
Members of expressions
Numerical constants.
Numerical variables.
String variables.
Numerical constants may not contain spaces.
Examples of correctly defined constants:
2; 3.344; -2.34; 1.234e+5; 1.2344E-32; 0.0034;
Examples of incorrectly defined constants:
2,34 – the comma is not allowed as the decimal symbol.
1.234 e+5 – inadmissible "space" symbol is used in a constant.
Note for local language users: in the exponential number representation, use only the US ASCII "E" or "e".
String constants.
A string constant is an arbitrary string entered in quotes:
"This is a string constant!"
Should a string constant include the quote symbol ("), it must be preceded by the backslash symbol (\).
"This is another \"string\" constant!"
The above is the way to enter a string constant, whose value is to read,
This is another "string" constant!
To have the backslash symbol a part of a string constant, it must be duplicated.
Example:
"This \\is\\ t\w\o\!"
The value reads,
This \is\ two!
Note that a single backslash is ignored throughout.
Instructions (operations) used in expressions
The string members can only be subject to the operation concatenate, or, simply, addition of two strings ( + )
"T-FLEX"+" CAD" = T-FLEX CAD
The numerical members are subject to common arithmetic operations, as
addition ( + )
subtraction ( - )
multiplication ( * )
division ( / )
unary negation (minus).
Examples of correctly defined expressions (followed by the result after the "=" sign):
2 + 3 = 5
5 - 9 = -4
Do not divide by zero. This will result in an error.
Use of "unary negation" operation is illustrated by the following example. Suppose, VAR_1 is equal to 5, then the following expression yields:
- VAR_1 = -5
An arbitrary number of spaces are allowed in expressions, for example,
5 * 3 + 2 = 17
Spaces make expressions more readable.
An important issue is the order of operations (precedence).
Thus, the resulting value of the following expression,
2 + 3 * 4
will be 14, rather than 20, because multiplication operation has higher precedence than addition. To change the order of operations, use parentheses. The previous expression can be modified in the following way in order to yield 20:
( 2 + 3 ) * 4
Proper use of parentheses helps avoiding unexpected results.
Power of ( ** or ^ )
Example:
2 ** 3 = 8
-3 ** 3 = -27
The following examples demonstrate specifics of this operation:
0 ** 17 = 0 (zero to any power is zero).
23 ** 0 = 1 (any value to the power of zero is one).
Errors may occur on evaluating this operation. The following message is output in such a case: "illegal power function in line 1".
Errors occur in the following cases:
-2 ** 3.4 (an attempt to raise a negative value to a fractional power).
23 ** 234344 (overflow error due to too large resulting value).
Modulo division ( % )
Example:
23 % 5 = 3
23.7 % 5.5 = 1.7
-23 % -5 = -3
23 % -5 = 3
-23 % 5 = -3
The result of the operation member1 % member2 is the remainder of dividing member1 by member2.
The value of member2 may not be zero. In the case member2 = 0, the error occurs, "Zero divide in line 1".
Besides the above-mentioned algebraic operations, logical (comparison) operations can be used in expressions. The result of a logical operation is the numerical value 1, if the relation defined by the operation is true, and 0 otherwise.
Logical operations
Greater than ( > )
Less than ( < )
Greater than or equal ( >= )
Less than or equal ( <= )
Inequality ( != )
Equality ( == )
Logical AND ( && )
Logical OR ( || )
Logical NOT ( ! )
Examples:
23 > 45 && 56 < 34
This example expresses the question: Is the number 23 greater than the number 45 and the number 56 less than the number 34? Obviously, the answer will be - no, therefore the value of this expression is zero.
The expression !VAR_1 is the same as VAR_1 == 0
Logical operations are usually used for comparing the value of a variable against a constant or a value of another variable. A shortcoming here is that only two values are possible as the result of evaluating a logical expression - 0 or 1.
Another form of using logical operations is a conditional statement.
A conditional statement has the following structure:
condition ? value1 : value2
Example:
VAR_1 > 100 ? 1 : -1
If the value of VAR_1 is greater than 100, then the statement will yield 1, otherwise it yields -1.
One can use arbitrary expressions for the condition, value1 and value2.
VAR_1 ? 1 : -1
or, just the same thing,
VAR_1 != 0 ? 1 : -1
VAR_1 != 0 && VAR_2 == 0) ? (VAR_3 + 1) : (VAR_4 -1)
Standard mathematical functions
ABS |
Return absolute value of |
abs ( -20 ) = 20 |
ACOS |
Calculate arccosine |
acos ( 0.5 ) = 60 |
ASIN |
Calculate arcsine |
asin ( 0.5 ) = 30 |
ATAN |
Calculate arctangent |
atan ( 1 ) = 45 |
CEIL |
Find integer ceiling |
ceil ( 3.98 ) = 4 |
COS |
Calculate cosine |
cos ( 60 ) = 0.5 |
FLOOR |
Find largest integer less than or equal to argument |
floor ( 3.13 ) = 3 |
HYPOT |
Calculate hypotenuse of right triangle |
hypot ( 3, 4 ) = 5 |
INT |
Round to nearest integer |
int ( 3.13 ) = 3 |
LOG |
Calculate natural logarithm |
log ( 1 ) = 0 |
LOG10 |
Calculate base-10 logarithm |
log10 ( 10 ) = 1 |
RACOS |
Calculate arccosine, in radians |
racos ( 0.5 ) = 1.0472 |
RASIN |
Calculate arcsine, in radians |
rasin ( 1 ) = 1.5708 |
RATAN |
Calculate arctangent, in radians |
ratan ( 2 ) = 1.10715 |
RCOS |
Calculate cosine, angle input in radians |
rcos ( 1 ) = 0.540302 |
ROUND(ARG1, ARG2 ) |
Round the value ARG1 with accuracy ARG2. |
Round ( 2.357, 0.25 ) = 2.25 Round ( 2.357, 0.1 ) = 2.4
|
RSIN |
Calculate sine, angle input in radians |
rsin ( 1 ) = 0.841741 |
RTAN |
Calculate tangent, angle input in radians |
rtan ( 1 ) = 1.55741 |
SIN |
Calculate sine |
sin ( 30 ) = 0.5 |
SQRT |
Find square root |
sqrt ( 16 ) = 4 |
TAN |
Calculate tangent |
tan ( 45 ) = 1 |
All functions except hypot and ROUND have one numerical argument. Function arguments can be substituted by any expression, including other function calls that result in real numbers.
SIN ( 10 + 10 + 10 ) = 0.5
SIN ( SQRT ( 900 ) ) = 0.5
The functions hypot and ROUND have two numerical arguments separated by a comma:
HYPOT ( 1 + 1 + 1, 1 + 1 + 1 + 1 ) = 5
The angle arguments of trigonometric functions are input in degrees, except for the functions whose names begin with "R".
T-FLEX CAD functions
ATOF("10.5") |
Convert the string "10.5" to the real number 10.5 |
ATOT(1.5,0.01,1,0)LTOT(1.5,0.01,1,0) SATOT(1.5) SLTOT(1.5) |
Convert the real number 1.5 to a string per the format specified by the rest three arguments |
FTOT(“variable name”) |
The function of conversion a numeric value to text. It converts a numeric variable or expression to the text using a comma instead of a dot. |
TGET()
|
This function allows the user to obtain textual properties of the elements: the name of the material of 3D operations, the values of text variables of the fragment. $text = tget(“0xD000001”,“$textvar”) – returns the string value from variable $textvar. $mater = tget(“Extrusion_0”,”Material”) – defines material for the operation “Extrusion _0”. |
TGETV ("system variable") |
Get the string value of a system variable or characteristics of the current drawing. The entire list of parameters whose values can be obtained with the help of the function tgetv, is given in the Attachment II of this chapter. |
TMGETV ("system variable") |
Get the string value of a system variable of the assembly if the current drawing is inserted there as a fragment. This function works similar to the function TGETV. |
ERROR("STRING") |
Display a user-defined message "STRING" on the screen |
WARN("STRING")or WARN("STRING","element name") |
Display a user-defined message "STRING" in the diagnostics window. Include the element name in the message. |
FTOA(10.5) |
Convert the real number 10.5 to the string "10.5" |
FIXNODENAME(n) |
Get the name of the fragment's node used for inserting the current document as a fragment by fixing points. This function is helpful for creating the libraries of logical and algorithmic schemes. It helps to orient direction of connecting arrow between elements. Input parameter: the number of the fragment's fixing point. |
GET("STR","P") |
Get the real value of the parameter P of the system element named STR. Instead of element’s name it is possible to specify its identifier (ID). The entire list of parameters whose values can be obtained with the help of the function get, can be found in the Attachment II of this chapter. |
GETV("NAME_Page",N) or GETV("NAME",N) |
Get the value of the service parameter of the document named NAME. N – is a value that will be returned by the function if it does not find the indicated parameter. Certain parameters are defined separately for each 2D page of the document. In this case, the ending “_Page” is added to the name of the parameter, where “Page” – is a name of desired page of the current document. If the page name is not specified, the parameter value will be returned for the first page. The entire list of parameters whose values can be obtained with the help of the function getv can be found in the Attachment II of this chapter. |
SETG/TSETG("NAME",N) |
Set the value N of a numerical/string global variable named NAME |
GETG/TGETG("NAME",N) |
Get the value of a numerical/string global variable named NAME. |
DISTANCE ("NAME1", "NAME2")
|
Get the distance between the entities specified by their names or Ids. |
MEASURE(("NAME1", "NAME2", "RELATION")
|
Get the value of requested relation "RELATION" between specified elements "NAME1" and "NAME2" (elements' names or IDs can be used as input values). |
ISFRAGMENT() |
Find the assembly hierarchy level of a fragment. For the current drawing, returns zero. |
MAX(N1,...,NN) |
Find the maximum value among the input set. |
MIN(N1,...,NN) |
Find the minimum value among the input set. |
STRLEN("STR") |
Find the number of characters in the string STR |
CHECK("file name", type) |
Find a file in the specified folders. |
TWORD("string", N) |
Get a word from a string. $NAME=TWORD("William Henry Gates", 2) – results in assigning the value Henry to the variable $NAME. |
TPART("string",N,N) |
Get a substring. |
TFIND("string1", "string2") |
Searches for the substring "string2" in the string "string1". Returns an integer value equal to the position number of the first substring occurrence, counted from 1. In the case of an error (the substring is not found) returns 0. |
TREPLACE("string1", "string2", "string3") |
Replaces the substring "string2" by the substring "string3" in the string "string1". Returns a character string, which is the input string with the entry replaced. |
GRAPH("Graph_name",X) |
Get the value of the function F(x), corresponding to the X argument value, for the graph named "Graph_name".
|
Database management functions
DBF(arg1, arg2, arg3) |
A dBASE database query. arg1 – database name. The database name can be defined by a string constant, variable or expression. arg2 – the name of the field to copy from. The field name can be defined by a string constant, variable or expression. arg3 – the condition for copying. The condition can be defined by a string constant, variable or expression. |
DBFWIN(arg1, arg2, arg3) |
A dBASE database query. Also converts text from DOS to WINDOWS format. Is used for correct handling of local language text. The parameters are analogous to those of the function dbf. |
FIND(database_field, condition_1, condition_2, ...) |
Get a value from the internal database The function returns the value of the specified field database_field of a record satisfying the conditions condition_1, condition_2. If no suitable record exists, the function outputs the error message "Wrong record number". |
MDB(arg1, arg2, arg3, arg4) |
An Access database request. arg1 - database name. The database name can be defined by a string constant, variable or expression. arg2 -the table name in the database. Can be defined by a string constant, variable or expression. arg3 - the name of the field to copy from. The field name can be defined by a string constant, variable or expression. arg4 - the condition for copying. The condition can be defined by a string constant, variable or expression. For example: mdb ( "c:\\T-FLEX_USER.mdb", "USER", "FULLNAME", "Code ={kod}" ) This means: select the value from the table “USER” of the database “T-FLEX_USER” from the field “FULLNAME” under condition that the value of the field “Code” is equal to the value of the variable kod. It is worth noting that the last operand of the function, specifying condition for record selection, can be written in the form of SQL query and then it must correspond to the WHERE clause of the SELECT command. If, upon writing the condition, the text variables are used, the expression will take the following form: mdb ( "c:\\T-FLEX_USER.mdb", "USER", "FULLNAME", "Post=\"{$Dol}\"" ). |
REC(condition) |
Get the Id of a record in the internal database. condition - a logical expression, taking values True or False. The expression may contain members - queries to the fields of the database. |
FREC(arg1, arg2, arg3, arg4) |
Get the Id of a record in the internal database or in the database by reference, where the value in the specified column matches most closely the specified value. arg1 – a database column, in which the search is performed. Must be of real or integer type; arg2 –sought value; arg3 –search option. Possible values: 0 –find nearest value; -1 –find nearest lesser value; 1 –find nearest greater value. arg4 –defines the column type to perform the search (the order in which the values occur in this column): 0 -the values are not in order; the search is performed over all database records; 1 –the values in the column are ordered ascending or descending. Once the difference between the value sought and the value in the current column of the database is greater than in the previous one, the search completes. The parameters arg3 and arg4 are optional. If these are skipped, the default values are used: arg3 = 0; search for nearest value; arg4 = 0; column not ordered; |
FTOT |
Executes the transformation of a real variable or expression into the text with the use of comma instead of a period. |
VAL(record_number, database_field, offset) |
Get the value from the internal database by the record Id. record_number -an arbitrary arithmetical expression, that yields an integer; database_field -a field query; offset (optional) - the number of the column for selecting value (calculated from the field specified in the second parameter). The offset can be assigned to a variable and can be both positive and negative. If offset value is 0, function returns the field specified in the second parameter. The same would happen if the third parameter is not used. |
#.<name> |
Get the number of records in the specified internal database |
The detailed description of T-FLEX CAD functions follows below. The database managing functions description are also available in the chapter "Databases".
Examples of function uses:
sin ( 30 ) = 0.5
min ( 5, 67, 34, 28, 0.67 ) = 0.67
SQrt ( 16 ) = 4
As evident in the last example, the function naming is case-insensitive.