Writing macros

Try to collect frequently used functionalities into macros.
Calling a macro object from many objects can reduce library size and increase soundness by reducing redundancy.

However, avoid creating macros with small functional addition to the previous abstraction level.
For example don’t create a block_1x1x1 macro for the generation of a 1m x 1m x 1m block.
This increases the number of macro calls needlessly and it may worsen transparency (not to mention speed issues).

Don’t ever use .gdl as macros, use macro objects (.gsm) instead.

When you call a macro, always use the call keyword
and put the name of the macro between quotation marks (e.g., call "m_rail_wired").
Do not create macro calls where the macro name is a parameter to avoid missing macros from archive files, and to support background conversion.

Be careful at using the parameter buffer.
Save the content of it at be beginning of the script if you want to use it.
Be sure that only the defined (return) values are in the buffer by the end of the script.

Macro return parameters

Starting with ARCHICAD 10, macros can return parameters to the caller object.
At the caller’s side, returned values can be collected using the returned_parameters keyword followed by a variable list.
The returned values will be stored in these variables in the order they are returned in the called macro.
The number and the type of the variables specified in the caller and those returned in the macro must not match.
If there are more variables specified in the caller, they will be set to 0 integer.
Type compatibility is not checked:
the type of the variables specified in the caller will be set to the type of the returned values.
If one of the variables in the caller is a dynamic array, all next values will be stored in it.
Note: the number of possible returned elements is limited at 32767 items.

In the macro object the end and the exit commands
define the values that have to be return to the caller object. See the example below.

Advanced parameters all

Starting with ARCHICAD 10, with parameters all keyword you can specify
extra parameters to be passed to the macro.
They will override the values coming from the caller or parameters of the called macro left to be default.
The macro can return parameters in this case also.

Faster macro call

Speed of parameter value transferring between the caller object and the macro was improved in 10.
Find out tips about utilization of macro call’s speed enhancements in the section called “Speed Issues”.

Macro call example

Script in the caller object.

call "myMacro" parameters all extraParam = 1
call "myMacro" parameters returned_parameters realWidth
call "myMacro" parameters all extraParam = 1 returned_parameters realWidth
call "myMacro" parameters all returned_parameters realWidth

Script in the macro.

realWidth = 2
end realWidth