cancel
Showing results for
Did you mean:
cancel
Showing results for
Did you mean:
BIM Coordinator Program (INT) April 22, 2024

# Find the next step in your career as a Graphisoft Certified BIM Coordinator!

GDL
About building parametric objects with GDL.

# Defining an array based on an integer parameter

Hello,

I'm trying to define an array by an integer. I want my array to have an equal amount of fields as an integer. I want to be able to use the array fields to define positions of elements so they need to hold the values while more are added or removed based on the integer.

This is what I have currently, however it locks the value to 0 as I would expect. I'm just not sure how to achieve what I'm after.

``````DIM num_position_x2[]
DIM num_position_y2[]
if (glob_modpar_name = "num_steps") or (glob_modpar_name = "total_distance") then

for i=1 to num_steps2
num_position_x2[i] = 0
num_position_y2[i] = 0
next i
parameters num_position_x2=num_position_x2
parameters num_position_y2=num_position_y2
endif``````

Thanks!

Windows 10
Legend

You're on the right track!

You will need to shadow the parameters. I have prepared a small but working example, which can be easily extended to suit all your needs.

``````dim EMPTYARRAY[]

if GLOB_MODPAR_NAME = "n_steps" then
! We have more steps than before
! init those values
x_pos[i] = 0.0
next i
else
! Less steps then before
dim _newx[]
for i=1 to n_steps
_newx[i] = x_pos[i]
next i
x_pos = EMPTYARRAY
x_pos = _newx
endif
endif

parameters \
x_pos = x_pos,

Lucas Becker | AC 27 on Mac | Author of Runxel's Archicad Wiki | Editor at SelfGDL | Developer of the GDL plugin for Sublime Text |
«Furthermore, I consider that Carth... yearly releases must be destroyed»
Learn and get certified!