Statements (Advanced Text Capabilities) Changed in Version 2016.1

www.CAD6.com

If enabled by the user, statements in texts are evaluated. This can be used, for example, to display and format the result of a Mathematical Term.

 

For that, a statement has to be enclosed in braces { }. Additionally, the opening brace { can be immediately followed by a control character which defines the type of the statement. The result of the evaluation is a text which is then used to replace the corresponding statement text. If the resulting text is empty the statement text is deleted. The assignment and the comment statement have no result text, here the statement text is always deleted.

 

 

Overview of Statement Types

Functional Statements

{=Var {Term}}

Assignment statement (term)

{=Var {$Text}}

Assignment statement (text)

{?Condition {Term1}{Term2}}

Conditional statement (term)

{?Condition {$Text1}{$Text2}}

Conditional statement (text)

{"{$Text1}{$Text2} {Term1}{Term2}}

Text comparison statement (term)

{"{$Text1}{$Text2} {$Text3}{$Text4}}

Text comparison statement (text)

{!Var {Term1}{Term2}}

Non-existence-statement (term)

{!Var {$Text1}{$Text2}}

Non-existence-statement (text)

{$Text} / {$}

Text or empty text statement, respectively

{§Term}

Variable name statement

{*Comment}

Comment statement

 

Numerical Term Statements (yield the result of the mathematical term)

{Term}

Maximum number of decimal places

{'Term}

Money amount with two fractional digits and digit grouping New in Version 2016.1

{%Term}

Rounded

{.Term}

Rounded, decimal point

{,Term}

Rounded, decimal comma

{+Term}

Rounded, decimal point, always with sign

{&Term}

Rounded, decimal comma, always with sign

{#Term}

Integer

 

C-Style Statements (yield the result of the mathematical term)

{f Term}

Floating-point value

{g Term}

Exponential value

{d Term}

Signed integer value

{x Term}

Unsigned hexadecimal value

{b Term}

Unsigned binary value

{s Term}

Formatted text

 

Var here means variable name without tilde characters. $Text denotes a text which is not evaluated as a numerical term, but initially copied only. Condition is a text which is interpreted as a numerical expression. If the result of this expression is zero then the condition is considered to be false (not fulfilled). Any other result means the condition is true (fulfilled). If the first condition is true then the first statement ({Term1} or {$Text1}) is executed, otherwise the second. Similarly for the non-existence-statement applies: If the variable does not exist or if it is empty the first statement ({Term1} or {$Text1}) is executed, otherwise the second.

 

Term denotes a text which is evaluated as a numerical term (control characters can be used to change the presentation of the result). The result of a mathematical term is always a number which is written to the result text according to its type (which is defined by the control character). An empty {} term always yields 0.0. If a syntax error occurs then the result text contains (***SYNTAX ERROR***) afterwards. For rounding the number of decimal places set by the user is used. If the decimal separator is not specified by the statement type the active decimal separator is applied.

 

If the result text is part of a text object which is displayed on screen, printed or exported, then the total text is evaluated as long as there are any statements. This also applies to the control texts of the CAM post-processor. That means, the resulting total text does not contains any braces { } afterwards, except those that have been inserted as explicit characters (\{ \}).

 

Most spaces in the statement texts are not required, they have been added only for better readability.

 

 

Samples

Assignment Statement

{=Var {Term}} or {=Var {$Text}}

 

The assignment statement is marked by the control character '=', it is followed by the variable name and a term or text statement. If the specified variable exists, the result of the mathematical term is assigned to that variable or the text is copied to the variable. If the variable does not exist a syntax error is output.

 

Example 1

Statement in the text:

{=Counter {# ~Counter~ + 15}}

 

Result text:

None

 

Explanation:

The variable "Counter" is incremented by 15. The assignment statement does not create an output.

 

Example 2

Statement in the text:

{=String {$This is a text}}

 

Result text:

None

 

Explanation:

The text "This is a text" is copied to the variable "String". The assignment statement does not create an output.

 

The statement {=Counter{0}} assigns zero to the variable "Counter". The statement {=String{$}} assigns an empty text to the variable "String", i.e. the variable's content is cleared.

 

Conditional Statement

{?Condition {Term1}{Term2}}

or

{?Condition {$Text1}{$Text2}}

 

The assignment statement is marked by the control character '?', it is followed by the numerical condition (which may include a complete term along with variables) and two term or text statements. If the condition is true, i.e. the numerical expression is non-zero, the first statement is used. On the other hand, if the condition is false, i.e. the numerical expression is zero, the second statement is used.

 

If the second statement does not exist, an appropriate default value is used. The type of the default value is derived from the first statement’s type (i.e. floating point number, integer number, or text), the value used is either 0 or an empty text.

 

Please note that in order to compensate the internal calculation inaccuracy values between -1.0e-10 and +1.0e-10 are also considered to be false.

 

Example 1

Statement in the text:

{? ~Value~!=0 {100/~Value~}{0}}

 

Result text (variable "Value" equals 5):

20.0

 

Result text (variable "Value" equals 0):

0.0

 

Explanation:

If the condition is true ("Value" is non-zero) the result of the division 100 divided by variable "Value" is output. Otherwise "0.0" is output.

 

Example 2

Statement in the text:

{? ~Value~ > 5 {$Big}{$Small}}

 

Result text:

Big or Small

 

Explanation:

If the condition is true ("Value" is greater than 5) the text "Big" is used. Otherwise the text "Small" is used.

 

Please note that the two text statements may include statements again.

 

Text Comparison Statement

{"{$Text1}{$Text2} {Term1}{Term2}}

or

{?{$Text1}{$Text2} {$Text3}{$Text4}}

 

The text comparison statement is marked by the control character '"', it is followed by two text statements and two term or text statements. If both texts are identical (case-insensitive), the first statement is used. On the other hand, if the texts are not identical, the second statement is used.

 

If the second statement does not exist, an appropriate default value is used. The type of the default value is derived from the first statement’s type (i.e. floating point number, integer number, or text), the value used is either 0 or an empty text.

 

Example 1

Statement in the text:

{"{$~Var1~}{$Content} {1}{0}}

 

Result text (variable "Var1" contains "Content"):

1.0

 

Result text (variable "Var1" does not contain "Content"):

0.0

 

Explanation:

If both texts are identical (case-insensitive) the value "1.0" is output. Otherwise "0.0" is output.

 

Example 2

Statement in the text:

{"{$~Var1~}{$Content} {$Yes}{$No}}

 

Result text:

Yes or No

 

Explanation:

If both texts are identical (case-insensitive) the text "Yes" is used. Otherwise the text "No" is used.

 

Please note that the two text statements may include statements again.

 

Non-Existence Statement

{!Var {Term1}{Term2}}

or

{!Var {$Text1}{$Text2}}

 

The assignment statement is marked by the control character '!', it is followed by the variable name and two term or text statements. If the variable is not defined or empty the first statement is used. If the variable does exist and if it is not empty the second statement is used.

 

If the second statement does not exist, an appropriate default value is used. The type of the default value is derived from the first statement’s type (i.e. floating point number, integer number, or text), the value used is either 0 or an empty text.

 

Example 1

Statement in the text:

{!Value {0}{100*~Value~}}

 

Result text if variable "Value" does not exist:

0

 

Result text if variable "Value" equals 0.75:

75,0

 

Example 2

Statement in the text:

{!Name {$Unknown}{$~Name~}}

 

Result text if the variable "Name" does not exist:

Unknown

 

Result text if the variable "Name" has the content "John Doe":

John Doe

 

Example 3

Statement in the text (using ~%"Name"~ for serial printing field access, see Variables):

{! %"Name" {$No Name}{$~%"Name"~}}

 

Result text if the serial printing field "Name" does not exist:

No Name

 

Result text if the serial printing field "Name" has the content "John Q. Public":

John Q. Public

 

Explanation:

You can use the non-existence-statement to define what happens if a variable does not exist or is empty.

 

This statement is especially useful to output serial printing fields and database requests. Please note that the two text statements may include statements again.

 

Text or Empty Text Statement

{$Text} / {$}

 

The text statement is marked by the control character '$'. The content of the statement is copied directly as a text, i.e. there is no evaluation. This especially useful inside conditional statements. Please note that the text to be copied starts directly after the $ character. Is the $ character directly followed by }, i.e. the text is empty, then an empty text is copied.

 

Example

Statement in the text:

{$This is a text}

 

Result text:

This is a text

 

Explanation:

The text is copied without any modification.

 

Please note that text statements may include statements again.

 

Variable Name Statement

{§Text}

 

The variable name statement is marked by the control character '§'. The content of the statement is interpreted as a variable name, i.e. is replaced by the value of the variable with this name. This allows to access variables via composed / concatenated names. This especially useful for indexed variable names. Please note that the variable name starts directly after the § character .

 

Example

Statement in the text:

{§Entry{#~Current~+1}}

 

Result text (the variable "Current" equals 2):

Content of the variable ~Entry3~.

 

Explanation:

The result of {#~Current~+1} is "3", resulting in a variable name of "Entry3".

 

Please note that these variable names may include statements again.

 

Comment Statement

{*Comment}

 

The comment statement is not output. This can be used to store hidden information in a drawing.

 

Example

Statement in the text:

{* This is a comment}

 

Explanation:

This statement is neither displayed on the screen, nor will it be printed or exported.

 

Numerical Term Statement, Maximum Number of Decimal Places

{Term}

 

The content of the braces is interpreted as a numerical expression, calculated and output with the maximum number of decimal places (currently 15).

 

Example

Statement in the text (the variable "Value" equals 1):

{~Value~/3}

 

Result text:

0.333333333333333

 

Please note that the decimal separator used depends on user settings, it can be either '.' or ','.

 

Numerical Term Statement, Money Amount

{'Term}

 

The content of the braces is interpreted as a numerical expression, calculated, rounded to two decimal places, and then output as a money amount with digit grouping.

 

Example

Statement in the text (the variable "Value" equals 199,998.0):

{' ~Value~*0.19}

 

Result text:

37,999.62

 

Please note that the decimal separator used depends on user settings, it can be either '.' or ','. The character for digit grouping is chosen accordingly. The number of decimal places is always 2.

 

Numerical Term Statement, Rounded

{%Term}

 

The content of the braces is interpreted as a numerical expression, calculated, rounded to the active number of decimal places (here five), and then output.

 

Example

Statement in the text (the variable "Value" equals 1):

{% ~Value~/3}

 

Result text:

0.33333

 

Please note that the decimal separator used depends on user settings, it can be either '.' or ','. The number of decimal places depends (in case of a text) on the text's active coordinate system, or (in case of a dimension) on the number of decimal places specified in the object's dimension parameters, or (in all other cases) on the active coordinate system. For control texts of the CAM postprocessor, the corresponding value from the postprocessor settings is used.

 

Numerical Term Statement, Rounded, Decimal Point

{.Term} or {.# Term}

 

The content of the braces is interpreted as a numerical expression, calculated, rounded to the active number of decimal places (here five), and then output. A point is used as decimal separator. If the '.' is followed by a hash, the decimal point will never be stripped, even if the rounded result is integer.

 

Example

Statement in the text (the variable "Value" equals 1):

{. ~Value~/3}

 

Result text:

0.33333

 

The number of decimal places depends (in case of a text) on the text's active coordinate system, or (in case of a dimension) on the number of decimal places specified in the object's dimension parameters, or (in all other cases) on the active coordinate system. For control texts of the CAM postprocessor, the corresponding value from the postprocessor settings is used.

 

Numerical Term Statement, Rounded, Decimal Comma

{,Term} or {,# Term}

 

The content of the braces is interpreted as a numerical expression, calculated, rounded to the active number of decimal places (here five), and then output. A comma is used as decimal separator. If the ',' is followed by a hash, the decimal comma will never be stripped, even if the rounded result is integer.

 

Example

Statement in the text (the variable "Value" equals 1):

{, ~Value~/3}

 

Result text:

0,33333

 

The number of decimal places depends (in case of a text) on the text's active coordinate system, or (in case of a dimension) on the number of decimal places specified in the object's dimension parameters, or (in all other cases) on the active coordinate system. For control texts of the CAM postprocessor, the corresponding value from the postprocessor settings is used.

 

Numerical Term Statement, Rounded, Decimal Point, Always with Sign

{+Term} or {+# Term}

 

The content of the braces is interpreted as a numerical expression, calculated, rounded to the active number of decimal places (here five), and then output. A point is used as decimal separator. The number is always preceded with a sign ('+' or '-'). Zero is always preceded with '+'. If the '+' is followed by a hash, the decimal point will never be stripped, even if the rounded result is integer.

 

Example

Statement in the text (the variable "Value" equals 1):

{+ ~Value~/3}

 

Result text:

+0.33333

 

The number of decimal places depends (in case of a text) on the text's active coordinate system, or (in case of a dimension) on the number of decimal places specified in the object's dimension parameters, or (in all other cases) on the active coordinate system. For control texts of the CAM postprocessor, the corresponding value from the postprocessor settings is used.

 

Numerical Term Statement, Rounded, Decimal Comma, Always with Sign

{&Term} or {&# Term}

 

The content of the braces is interpreted as a numerical expression, calculated, rounded to the active number of decimal places (here five), and then output. A comma is used as decimal separator. The number is always preceded with a sign ('+' or '-'). Zero is always preceded with '+'. If the '&' is followed by a hash, the decimal comma will never be stripped, even if the rounded result is integer.

 

Example

Statement in the text (the variable "Value" equals 1):

{& ~Value~/3}

 

Result text:

+0,33333

 

The number of decimal places depends (in case of a text) on the text's active coordinate system, or (in case of a dimension) on the number of decimal places specified in the object's dimension parameters, or (in all other cases) on the active coordinate system. For control texts of the CAM postprocessor, the corresponding value from the postprocessor settings is used.

 

Numerical Term Statement, Integer

{#Term}

 

The content of the braces is interpreted as a numerical expression, calculated, rounded to zero decimal places (integer), and then output.

 

Example

Statement in the text (the variable "Value" equals 2):

{# ~Value~/3}

 

Result text:

1

 

Floating-Point Value

{f Term} or {fX Term} or {f. Term} or {f.X Term} or {f, Term} or {f,X Term}

 

The content of the braces is interpreted as a numerical expression, calculated, and output as floating point number. If the 'f' character is followed by a point or comma, this indicated the decimal separator to be used. If the 'f' character, or the point or comma, respectively, are directly followed by an integer number, this number denotes the number of fractional digits to be output. If no number is given, the current default number of decimal places is used.

 

Example 1

Statement in the text (the variable "Value" equals 2):

{f,3 ~Value~/3}

 

Result text:

0,667

 

Example 2

Statement in the text (the variable "Value" equals 2):

{f.8 ~Value~/3}

 

Result text:

0.66666667

 

Exponential Value

{g Term} or {gX Term} or {g. Term} or {g.X Term} or {g, Term} or {g,X Term}

 

The content of the braces is interpreted as a numerical expression, calculated, and output as exponential or floating point number (using the shorter version). If the 'g' character is followed by a point or comma, this indicated the decimal separator to be used. If the 'g' character, or the point or comma, respectively, are directly followed by an integer number, this number denotes the number of mantissa places to be output. If no number is given, the current default number of mantissa places is used.

 

Example 1

Statement in the text (the variable "Value" equals 2):

{g,3 ~Value~/3*1e20}

 

Result text:

6,67e+019

 

Example 2

Statement in the text (the variable "Value" equals 2):

{g.8 ~Value~/3*1e20}

 

Result text:

6.6666667e+019

 

Signed Integer Value

{d Term} or {dX Term}

 

The content of the braces is interpreted as a numerical expression, calculated, rounded, and output as a signed integer number. If the 'd' character is directly followed by an integer number, this number denotes the number of digits to be output (filled with preceding zeros). If no number is given, the required number of digits is used.

 

Example 1

Statement in the text (the variable "Value" equals 2):

{d ~Value~*600}

 

Result text:

1200

 

Example 2

Statement in the text (the variable "Value" equals 2):

{d8 ~Value~*600}

 

Result text:

00001200

 

Unsigned Hexadecimal Value

{x Term} or {xX Term}

 

The content of the braces is interpreted as a numerical expression, calculated, rounded, and output as an unsigned hexadecimal number. If the 'x' character is directly followed by an integer number, this number denotes the number of digits to be output (filled with preceding zeros). If no number is given, the required number of digits is used.

 

Example 1

Statement in the text (the variable "Value" equals 2):

{x ~Value~*600}

 

Result text:

4b0

 

Example 2

Statement in the text (the variable "Value" equals 2):

{x8 ~Value~*600}

 

Result text:

000004b0

 

Unsigned Binary Value

{b Term} or {bX Term}

 

The content of the braces is interpreted as a numerical expression, calculated, rounded, and output as an unsigned binary number. If the 'b' character is directly followed by an integer number, this number denotes the number of digits to be output (filled with preceding zeros). If no number is given, the required number of digits is used.

 

Example 1

Statement in the text (the variable "Value" equals 2):

{b ~Value~*600}

 

Result text:

10010110000

 

Example 2

Statement in the text (the variable "Value" equals 2):

{b16 ~Value~*600}

 

Result text:

0000010010110000

 

Formatted Text

{s Term} or {sX Term} or {s-X Term}

 

The content of the braces is interpreted as a text. If the 's' character is directly followed by an integer number, this number denotes the number of characters to be output (left-aligned with trailing spaces). If the 's' character is directly followed by a '-' and an integer number, this number denotes the number of characters to be output (right-aligned with preceding spaces). If no number is given, the text is used directly. Please note that the text to be copied starts only after the whitespace behind the 's' character and possible numbers.

 

Example 1

Statement in the text:

{s Text}

 

Result text:

Text

 

Example 2

Statement in the text:

{s10 Text}

 

Result text (spaces highlighted by underlining):

Text______

 

Example 3

Statement in the text:

{s-10 Text}

 

Result text (spaces highlighted by underlining):

______Text

 

Example 4

Statement in the text:

{s10 ExtraLongText}

 

Result text:

ExtraLongT

 

Example 5

Statement in the text:

{s-10 ExtraLongText}

 

Result text:

raLongText

 

Starting with Version 2019.1, all texts, names, variables, and attributes are Unicode-enabled. In memory, they are stored in UTF-16 format, in the CAD6 file format in UTF-8 format.

 

CAD6interface 2024.2 - Copyright 2024 Malz++Kassner® GmbH