Overview |
NX Knowledge Fusion contains the special character set shown in the following table.
Special Character |
Description |
Example |
" (Double quote) |
Begins or terminates a string. To insert non-standard characters into a string, the tilde (~) is an escape character. The NX Knowledge Fusion language uses the "~" (tilde) character as an "escape" character within strings, so that strings may include characters that are normally treated specially, such as double quotes. A tilde introduces an escape sequence, which must be one of the following forms: In source: Result in string: "Test ~~ string" Test ~ string "Test ~" string" Test " string "Test ~t string" Test <tab> string "Test ~n string" Test <newline> string "Test ~x40 string" Test @ string "Teststring" Test<newline>string Where <tab> and <newline> represent the operating system characters for those control codes. Strings can span multiple lines. A newline in a string (not escaped) is treated like any other non-escaped character. Backslashes are not escape characters, and can be used as any other character. The ~xHH sequence allows any 8-bit code to be inserted into the string, where HH is the hexidecimal representation for the character. This allows any other non-printing or extended-set character to be placed in strings. NX Knowledge does not support multi-byte characters. |
In the following example, a list of strings is output to a file, one string per line, and enclosing the strings in the file in double quotes. DefClass: test (ug_base_part); (list) str_list: {"a"; "b"; "c"; "d"; "e"; "f"; "g"; "h"; "i"}; (integer) str_out: @{ $file << openfile("C:\work\teststr.txt"; Write); loop { for $aaa in str_list:; # double-quote, string, double-quote, newline do write("~"" + $aaa + "~"~n"; $file); }; closefile($file); }; |
# (Pound sign, or Number sign) |
Begins or ends a comment. If the following character is not "+" or "-" , it begins a comment which extends to the end of the line. (Number Parameter) radius: ; #This is a comment. If the following character is "+", it begins a comment which extends to the matching "#-". In the following example, all four lines are ignored. #+ (Number Parameter) diameter: ; (Name Parameter) style: ; #- Comments immediately preceding a rule are assumed to belong to that rule. NX Knowledge Fusion keeps the comment and rule together. # This comment belongs to the following rule (radius). (Number Parameter) radius: ; # This comment belongs to diameter. (Number Parameter) diameter: ; |
(List) data: @{ $file << OpenFile(filename:; Read); $data << ReadSimpleDataFile($file); CloseFile($file); $data; }; |
$ (Dollar sign) |
Precedes the name of a variable, in a block or loop. |
(List) data: @{ $file << OpenFile(filename:; Read); $data << ReadSimpleDataFile($file); CloseFile($file); $data; }; |
% (Percent sign) |
A normal alphabetic character, except when used (twice) at the beginning of a name. Use of %% (two percent signs) at the beginning of a name is reserved for internal NX Knowledge Fusion names. The NX Knowledge Fusion user interface treats all names beginning with % in special ways. For example, the user interface does not display attributes beginning with %. |
|
& (Ampersand) |
The "and" operator, used for joining two boolean expressions in an "and" condition. |
(Name) size: if ((width: > 10) & (length: > 10)) then LargeStyle else SmallStyle; Generally the boolean expressions are each parenthesized, for clarity, as above. |
( ) (Parentheses) |
Parentheses are used to indicate operator precedence. (Number) aaa: 2*3+4*5; # Result is 26 (Number) bbb: 2*(3+4)*5; # Result is 70 Parentheses may be used to group any calculation for clarity, even if not technically necessary: (Number) aaa: (2*3)+(4*5); # Result is 26 (Number) ccc: 3 + (sin(30)); # Result is 3.5 Parentheses are also used to group syntactically similar items, including:
|
|
* (Asterisk) |
The asterisk is used for multiplication. Integer * Integer -> Integer Integer * Number -> Number Vector * Numeric -> Vector (scaling a vector) Vector * Vector -> Vector (cross product) |
|
+ (Plus sign) |
The plus sign is used for addition. Integer + Integer -> Integer Integer + Number -> Number Number + Number -> Number List + List -> List (list concatenation) Point + Vector -> Vector (translating a point) Vector + Vector -> Vector String + String -> String (string concatenation) |
|
- (Hyphen or minus sign) |
The minus sign is used for subtraction and negation. Integer - Integer -> Integer Number - Integer -> Number Point - Vector -> Point Point - Point -> Vector Integer -> Integer (the negated value) Number-> Number (the negated value) Boolean-> Boolean (the opposite value) Vector -> Vector (the reverse direction) |
# Use minus for ordinary subtraction. (Number) intermediateHeight: totalHeight: - footerHeight:; # Use minus to negate a number. (Number) negative: -size:; # Use minus to operate on points. (Vector) direction: rightPoint: - leftPoint:; # Use minus to reverse a vector. (Vector) oppositeDirection: -direction:; # Use minus to "negate" boolean values. (Boolean) falseStatement: 1=2; (Boolean) trueStatement: -falseStatement:; Note that while Strings and Lists can be concatenated by using "+", there is no operation that corresponds to "-". |
. (Period |
The period is used for dot-products of vectors: Vector . Vector -> Number The period is also used for decimal points within numbers: 3.14 |
|
/ (Slash) |
The slash is used for division. Integer / Integer -> Number Number / Integer -> Number Vector / Number -> Vector |
|
[ ] (Square brackets) |
Square brackets are reserved for future extensions. |
|
^ (Caret or up-arrow) |
The caret is used for exponentiation. Defclass: Square (BaseRectangle); (Number Parameter) size: ; (Number) area: size:^2; |
|
0 - 9 (Digits) |
Numbers are composed of digits, decimal points, an optional leading plus or minus sign, and an optional trailing exponent (scientific notation). |
|
: (colon) |
The colon is used for references. In some contexts, it is also used as the terminator for a name. In multi-level references, there must not be any whitespace in between the names. Right: arc_1:center: Wrong: arc_1 :center: |
|
; (semi-colon) |
The semi-colon is used as the terminator at the end of each rule, as a separator between function arguments and as a separator between items inside braces (i.e., within blocks, loops, and lists). |
|
, (comma) |
The comma can be used in place of a semi-colon for separating function arguments and members of a list. |
|
< (less-than) |
The less-than operation is used to compare two numbers or integers. In certain contexts, the less-than sign is used as an "angle bracket" to enclose sets of names. |
|
<< (two less than signs) |
The combination of two less than signs is used for assignment of variables within blocks. |
|
<= (less-than or equal to) |
The less-than-or-equal-to operation is used to compare two numbers or integers. |
|
= (equal sign) |
The equal operation is used to compare two objects. Booleans are compared to see if they are the same value. Numbers and Integers are compared to see if they are the same value. Lists are compared for equality recursively. Each item in the list is compared for equality to the corresponding item in the second list. If the items are both sublists, the sublists are recursively compared for equality. The lists must have the same contents, in the same order. Names are compared to see if they are the same name. As with all operations on Names, the case of the letters is ignored. Instances are compared to see if "they" are actually the same instance. There is no general way to determine if two instances have the same values in all their attributes. Points are compared to see if they are within a tolerance of each other. The tolerance is currently set to 0.0001 and cannot be changed by users. Strings are compared for equality using a case-insensitive test. User data is compared for numeric equality. Vectors are compared for equality by determining if they have the same direction and magnitude; by unitizing the first vector, normalizing the second to the first, and determining if the two resulting vectors (treated as points) are within 0.0001 of each other. There is currently no explicit "not equal" symbol. Use a minus sign to negate the expression, like this: (Boolean) useManual?: -(suppliedValue: = Automatic); |
|
> (greater-than) |
The greater-than operation is used to compare two numbers or integers. In certain contexts, the greater-than sign is used as an "angle bracket" to enclose sets of names. |
|
>= (greater-than or equal to) |
The greater-than-or-equal-to operation is used to compare two numbers or integers. |
|
!= (not equal to) |
The not-equal-to operation is used to compare the inequality of two objects. |
|
? (question mark) |
The question mark is an ordinary alphabetic character, except that it cannot be the first character in a Name. It is a NX Knowledge Fusion convention to use a question mark at the end of a name to indicate a boolean attribute, parameter or function. |
|
_ (underscore) |
The underscore is an ordinary alphabetic character. It can even be the first character in a Name, and is never treated specially. |
|
@{ } (at-sign with curly brackets) |
The combination of an at-sign with an open curly brace indicates an expression block. |
|
{ } (curly brackets) |
Curly brackets with no special preceding character or word indicate creation of a list. The expressions within the brackets are evaluated, and their values comprise the contents of the list. # A simple list (all constants). (List) initialData: {1; 2; 3}; # A list containing sublists (also all constants). (List) pairs: {{a; 1}; {b; 2}; {c; 3}}; # The curly-bracket operators allow sub-expressions to be evaluated. (List) sizeData: {length:; width:; height:}; |