Libraries & objects
About Archicad and BIMcloud libraries, their management and migration, objects and other library parts, etc.

Could anyone give quick lesson on arrays? (length of array)

matjashka
Advocate
I read a few really good threads on arrays, but I'm still a bit confused.

Simple concept: I need to CALL an object a few times at user-defined spaces given in 1-dimensional array.
User manually inserts N amount of fields in an array in Object Parameters, like:
1'-0"
2'-8"
13'-6"
...and so forth

I'd like to use a FOR loop that inserts the CALLed object N times at specific intervals. Is this the correct approach? Thank you!
Matt Krol [LinkedIn]
BHMS Architects and Planners, Chicago
AC 10 ... 26 USA
7 REPLIES 7
Anonymous
Not applicable
Tip:
nSpaces=0 !conts add commands
for kont=1 to N do
add arrayName[kont], 0.000, 0.000
call callName
nSpaces=nSpaces+1
next kont
del nSpaces
matjashka
Advocate
Ilder,
Thank you,
if I'm understanding your response correctly, the basic loop example you shared with me assumes that N is a pre-defined number.
That's not the case -- I would like N to be automatically generated based on number of rows in the array when the array is parsed. How do I make the GDL engine return that number?
1) Parse the array
2) Calculate N of array elements in a column
3) for i=1 to N space objects at defined values

Next time the user adds or deletes a row, N is re-calculated. I'm sure it's simple, I'm just missing that bit.
Matt Krol [LinkedIn]
BHMS Architects and Planners, Chicago
AC 10 ... 26 USA
Anonymous
Not applicable
Hello,

You can declare dynamic arrays just using
dim xxx[]
or
dim yyy[][]
The variables vardim1() and vardim2() return the array length

For example
rows= vardim1(xxx)
or
columns= vardim2(xxx)
Hope this helps.
matjashka
Advocate
Thank you, Juha.
I eventually reached the part of GDL manual where they explain how to build arrays. Let me explain myself a bit more:
See the attached screenshot with an array called myarray[4]

My question is: I don't want to hard code the number in brackets. It can be [4] or [1] or [52] but I do not know how to pass it to my FOR loop without hard coding it, because I'd like my users to add or delete as many rows as they want.

Is this possible at all...?
array_length.jpg
Matt Krol [LinkedIn]
BHMS Architects and Planners, Chicago
AC 10 ... 26 USA
Anonymous
Not applicable
Hello,
Do not know if this is the case - just one
example getting values from one array to
another

!--value or master script
dim xxx[]
n= 0

for i = 1 to vardim1(myarray)
  if myarray > 0 then   !--filter what is included to the array 'xxx'
    n= n+1
    xxx = myarray
  endif
next i

!--make it a value list
values 'mylist' xxx
matjashka
Advocate
Juha wrote:

for i = 1 to vardim1(myarray)
GDL wrote:
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.
Awesome - *this* is exactly what I was looking for. I saw vardim1 in the manual, but didn't really know how it applied to my problem.

THANK YOU very much, Juha!
Matt Krol [LinkedIn]
BHMS Architects and Planners, Chicago
AC 10 ... 26 USA
Erich
Booster
There is a very good discussion of array sizing with examples here too.
Erich

AC 19 6006 & AC 20
Mac OS 10.11.5
15" Retina MacBook Pro 2.6
27" iMac Retina 5K

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!