Length/Size of one of the sub-arrays of a multi-dim array
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-13
08:44 AM
- last edited on
2021-09-14
09:00 AM
by
Noemi Balogh
Is there a way to get the length/size of a sub-array of a multi-dimensional array?
DIM myArray[][] myArray[1][1] = 500 myArray[1][2] = 510 myArray[2][1] = 600 myArray[2][2] = 610 myArray[2][3] = 620 myArray[3][1] = 700 myArray[3][2] = 710 myArray[3][3] = 720 myArray[3][4] = 730VARDIM1(myArray[1])
I tried VARDIM2(myArray[1]) also but it doesn't give the required output.
- Labels:
-
Library (GDL)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-13 09:34 AM
dushyant wrote:I think so.
Barry, so you mean it builds like a matrix of 3x4 cells and assigns 0 to any non-assigned cells?
If you created an array in the parameter list it would look like this.
Barry.
Versions 6.5 to 27
i7-10700 @ 2.9Ghz, 32GB ram, GeForce RTX 2060 (6GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-13 09:36 AM
Just wondering if we can loop through the values of a dictionary, like we do through an array:
FOR i = 1 TO VARDIM1(myArray) ...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-13 09:41 AM
dushyant wrote:
Got it Barry, thanks.
Just wondering if we can loop through the values of a dictionary, like we do through an array:
FOR i = 1 TO VARDIM1(myArray) ...
I have not delved into DICTIONARY yet so I have no idea.
You can loop through the array as you have shown but just ignore if the value is zero.
Barry.
Versions 6.5 to 27
i7-10700 @ 2.9Ghz, 32GB ram, GeForce RTX 2060 (6GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-13 09:48 AM
Barry wrote:
You can loop through the array as you have shown but just ignore if the value is zero.
Something like this?
This will just print the values in each dimension but not the zero values.
FOR n = 1 TO VARDIM1(myArray) FOR i = 1 TO VARDIM2(myArray) IF myArrayBarry.<> 0 THEN PRINT myArray ENDIF NEXT i NEXT n
Versions 6.5 to 27
i7-10700 @ 2.9Ghz, 32GB ram, GeForce RTX 2060 (6GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-13 09:52 AM
Uninitialized array element at index: [1][3](as I didn't set [1][3], but only up to [1][2])
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-13 10:05 AM
In that case, multi-dim arrays might not be helpful for what I am trying to do. Thanks guys for the help.No. Unfortunately not.
Can dictionaries be looped through?
and keys can't be reached by variables... I suggested it, but graphisoft refused

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-13 10:20 AM
And two-dimensional arrays: myArray[][], myArray[1][1], myArray[1][2], myArray[2][1], myArray[2][2]...
If you refer two-dimensional array in your script as one dimensional - script won't work and will give an error. That means if you have let say 3x4 array: myArray[3][4] you cannot use anywhere in the script myArray[1]
And, by the way, three-dimensional arrays in mathematic called 'matrix' - like movie. It's when you have z to your array. Just imagine - array tables stack on top of each other. Or multipage excel spreadsheet...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-13 10:28 AM
dushyant wrote:
Barry, I had tried that but it seems to still scan through the part inside the IF statement (even if the condition is false) and gives an error:Uninitialized array element at index: [1][3](as I didn't set [1][3], but only up to [1][2])
This is all I have written in the Master script.
No parameters in the parameter list and nothing in any other script.
The just open the 2D or 3D preview and it will print ... 500, 510, 600, 610, 700, 710, 720, 730
No error messages that I see.
Barry.
Versions 6.5 to 27
i7-10700 @ 2.9Ghz, 32GB ram, GeForce RTX 2060 (6GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-13 10:34 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-13 11:05 AM
dushyant wrote:
Strange, I get this error..
What version of Archicad are you using?
I did this in 22 and just checked in 25 and still no error messages.
Barry.
Versions 6.5 to 27
i7-10700 @ 2.9Ghz, 32GB ram, GeForce RTX 2060 (6GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11