Robust GDL objects catch invalid states before they lead to runtime errors. The most common error sources and their safeguards:


Pen Colors (PEN)

Pen numbers must always be ≥ 1 in Archicad (except for background pens). Values of 0 or negative numbers cause errors.

GDL
! --- PEN must not be less than 1 
IF pen < 1 THEN pen = 1 
! --- The same applies to all derived pen parameters 
IF post_fill_pen < 1 THEN post_fill_pen = 1 
IF post_fill_bg_pen < 1 THEN post_fill_bg_pen = 1 
IF line_pen < 1 THEN line_pen = 1

Missing Fill (FILL)

If an object references a fill by name, it may be missing in the target project. Before use, check whether it exists:

GDL
! --- Check if "Mix-Fill 50 %" exists in the project 
fill50 = IND(FILL, "Mix-Fill 50 %") 
IF fill50 > 0 THEN 
    framefill = fill50 
ELSE 
    framefill = 1 ! Fallback to first available fill 
ENDIF 

! Subsequently query the name
rrr = REQUEST("Name_of_Fill", framefill, fillName)

Note: IND() returns 0 if the element was not found – this case must always be handled.

Line Weights (LINE_TYPE)

Similarly, line types may also be missing in the target project:

GDL
! --- Check if the line type exists
linType = IND(LINE_TYPE, "Dashed Line")

IF linType < 1 THEN linType = 1    ! Fallback to standard line

Division and Modulo Operations

Division by zero is a classic runtime error:

GDL
! --- Safeguard division
eps = 0.0001
IF ABS(divisor)  eps THEN
    result = numerator / divisor
ELSE
    result = 0    ! or set a meaningful default value
ENDIF

! --- The same applies to MOD
IF count > 0 THEN
    remainder = value MOD count
ELSE
    remainder = 0
ENDIF

Array Bounds

Accesses outside an array index lead to runtime termination:

GDL
! --- Check index bounds before array access
IF idx >= 1 AND idx <= VARDIM1(myArray) THEN
    value = myArray[idx]
ELSE
    value = 0    ! Fallback
ENDIF

Geometric Minimum Values

Zero lengths, widths, and heights produce degenerate geometry:

GDL
! --- Ensure minimum dimensions
IF A < 0.001 THEN A = 0.001
IF B < 0.001 THEN B = 0.001
IF ZZYZX < 0.001 THEN ZZYZX = 0.001

! --- Keep angles within valid range
IF angle < 0    THEN angle = 0
IF angle > 360 THEN angle = 360

Materials and Surfaces

GDL
! --- Check if the material exists in the project
matIdx = IND(MATERIAL, mat_name)

IF matIdx < 1 THEN
    matIdx = 1    ! Fallback to first available material
ENDIF

MATERIAL matIdx

REQUEST Queries

REQUEST() returns 0 if the query fails – the result must always be checked:

GDL
! --- Safeguard REQUEST return value
rrr = REQUEST("Name_of_Fill", framefill, fillName)

IF rrr <> 1 THEN
    fillName = "unknown fill"    ! Fallback text
ENDIF

Overview: Safeguarding Rules

Type Error Source Safeguard
PEN Value < 1 IF pen < 1 THEN pen = 1
FILL / LIN / MATERIAL Name not in project Check IND(), fallback to index 1
Division / MOD Divisor = 0 IF divisor <> 0 THEN ...
Array Index outside bounds Check VARDIM1() / VARDIM2()
Geometry Value = 0 or negative Enforce minimum value
REQUEST Query fails Check return value rrr for = 1

Principle: Any value that comes from a user parameter, a REQUEST, or an IND call should be treated as potentially invalid and validated before use.