Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
05 ArchiCAD 11 GDL Reference Guide.pdf
Скачиваний:
60
Добавлен:
11.03.2015
Размер:
3.22 Mб
Скачать

EXPRESSIONS AND FUNCTIONS

All parameters of GDL shapes can be the result of calculations. For example, you can define that the height of the cylinder is five times the radius of the cylinder, or prior to defining a cube, you can move the coordinate system in each direction by half the size of the cube, in order to have the initial origin in the center of the cube rather than in its lower left corner. To define these calculations, GDL offers a large number of mathematical tools: expressions, operators and functions.

EXPRESSIONS

You can write compound expressions in GDL statements. Expressions can be of numerical and string type. They are constants, variables, parameters or function calls and any combination of these in operators. Round bracket pairs (( )) (precedence 1) are used to override the default precedence of the operators.

Simple type variables can be given numerical and string values, even in the same script, and can be used in numerical and string type expressions respectively. Operations resulting in strings CANNOT be used directly as macro names in macro calls, or as attribute names in material, fill, line type or style definitions. Variables given a string value will be treated as such and can be used wherever string values are required. If later in the script the same variable is given a numerical value, it will be usable in numerical expressions only until it is given a string value again. Where possible, in the precompilation process the type of the expressions is checked.

GDL supports one and two dimensional arrays. Variables become arrays after a declaration statement, in which their dimensions are specified.

DIM

DIM var1[dim_1], var2[dim_1][dim_2], var3[ ], var4[ ][ ], var5[dim_1][ ],

var5[ ][dim_2]

After the DIM keyword there can be any number of variable names separated by commas. var1, var2, ... are the array names, while the numbers between the brackets represent the dimensions of the array (numerical constants). Variable expressions cannot be used as dimensions. If they are missing, the array is declared to be dynamic (one or both dimensions).

Library part parameters can also be arrays. Their actual dimensions are specified in the library part dialog. Parameter arrays do not have to be declared in the script and they are dynamic by default. When referencing the library part using a CALL statement, the actual values of an array parameter can be an array with arbitrary dimensions.

The elements of the arrays can be referenced anywhere in the script but if they are variables, only after the declaration. var1[num_expr] or var1

var2[num_expr1][num_expr2] or var2[num_expr1] or var2

Writing the array name without actual indices means referencing the whole array (or a line of a two-dimensional array) which is accepted in some cases (CALL, PRINT, LET, PUT, REQUEST, INPUT, OUTPUT, SPLIT statements). For dynamic arrays there is no limitation for the actual index value. During the interpretation, when a non-existing dynamic array element is given a value, the necessary quantity of memory is allocated and the missing elements are all set to 0 (numerical).

ArchiCAD 11 GDL Reference Guide

195

Expressions and Functions

Warning! This may cause an unexpected out of memory error in some cases. Each index - even of a possibly wrong, huge value - is considered valid, since the interpreter is unable to detect the error condition. A non-existing dynamic array element is 0 (numerical).

Arrays having a fixed dimension are checked for the validity of the actual index on the fixed dimension. Fixed arrays cannot be given whole dynamic array values. However, dynamic arrays that are given whole array values will take on those values. This also applies to some statements where whole array references can be used as return parameters. (REQUEST, INPUT, SPLIT).

Array elements can be used in any numerical or string expression. They can be given string or numerical values. Indices start with 1, and any numerical expression can be used as an index.

Array elements can be of different simple types (numerical, string, group). The type of the whole array (‘main’ type) is the type of its first element ([1] or [1][1]). Parameter and global variable arrays cannot be of mixed type.

VARDIM1(expr)

VARDIM1(expr)

VARDIM2(expr)

VARDIM2(expr)

These functions return as integers the actual dimension values for the (array) expression specified as a parameter. They must be used if you want to handle correctly all actual elements of a dynamic array or an array parameter. If no element of a dynamic array was previously set, the return value is 0. For one-dimensional arrays VARDIM2 returns 0.

196

ArchiCAD 11 GDL Reference Guide

Expressions and Functions

Examples for numeric expressions:

Z 5.5

(+15) -X A*(B+C)

SIN(X+Y)*Z

A+R*COS(I*D) 5' 4"

SQR (x^2 + y^2) / (1 - d) a + b * sin (alpha) height * width

Examples for string expressions:

"Constant string"

name + STR ("%m", i) + "." + ext string_param <> "Mode 1"

Examples for expressions using array values:

DIM tab [5], tab2 [3][4] ! declaration tab [1] + tab [2]

tab2 [2][3] + A PRINT tab

DIM f1 [5], v1[], v2[][]

v1[3] = 3 !v1[1] = 0, v1[2] = 0, array of 3 ! elements

v2[2][3] = 23 ! all other elements(2 X 3) = 0 PRINT v1, v2

DIM f1 [5], v1[], v2[][] FOR i = 1 TO VARDIM1(f1)

f1 [i] = i NEXT I

v1 = f1

v2 [1] = f1 PRINT v1, v2

ArchiCAD 11 GDL Reference Guide

197