We value your input!
Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey

GDL
About building parametric objects with GDL.

Length/Size of one of the sub-arrays of a multi-dim array

dushyant
Enthusiast
Hi
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] = 730
VARDIM1(myArray[1]) !gives 4, but I need the size of just myArray[1], which is 2

I tried VARDIM2(myArray[1]) also but it doesn't give the required output.
32 REPLIES 32
Barry Kelly
Moderator
Actually I get that error message if I run the 'Check Script' option.
But not when I actually view the preview or place the object.
I'm not sure if that is something that can just be ignored (I don't like ignoring error messages).
Must be something to do with the fact not all of the array values are set.

Barry.
One of the forum moderators.
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
You have to declare all elements in the array if you are going to query the whole array with a loop.
Declare a local array (_myArray[][]) and set its size using a loop nominating every value as a default or as the actual array value. Then pass this local array to you array (myArray[][]) using parameter myArray = _myArray.
This means you have a fully declared array ready to then push your values to.
So basically you just missed the first step of forcing the array to exist with all cells holding memory.
Creator of Cadswift's parametric GDL libraries
Creator of Infinite Openings and Component Catalogues
Push the envelope & watch it bend
website: https://cadswift.com.au/
YouTube: https://www.youtube.com/user/CADSwift/playlists
dushyant
Enthusiast
Barry, yes, the error comes on checking the script. (I'm on v24)

Kristian, that's a way around it, yes. When you say 'local array' I believe you are comparing with the parameters array.. Anyway, all my arrays in this situation are locally created. This would mean so many repeated loops and copies of arrays.
dushyant wrote:
This would mean so many repeated loops and copies of arrays.
Not so many just one to declare the whole thing (5 line loop statement) and then one populating the values with whatever logic you require. The master script of Infinite Openings is laden with declared and then populated arrays. The tool must dynamic shift between varying configurations via the catalogues and this issue was one that would break it many times until I finally ironed out the last not fully declared array, luckily some time ago.
Creator of Cadswift's parametric GDL libraries
Creator of Infinite Openings and Component Catalogues
Push the envelope & watch it bend
website: https://cadswift.com.au/
YouTube: https://www.youtube.com/user/CADSwift/playlists
also when you do declare your array, invert the loop doing for example: for i = arrayDim1 to 1 step -1
It makes it generate faster because you have already set the full dimension in the first run of the loop.
Creator of Cadswift's parametric GDL libraries
Creator of Infinite Openings and Component Catalogues
Push the envelope & watch it bend
website: https://cadswift.com.au/
YouTube: https://www.youtube.com/user/CADSwift/playlists
dushyant
Enthusiast
Kristian wrote:
also when you do declare your array, invert the loop doing for example: for i = arrayDim1 to 1 step -1
It makes it generate faster because you have already set the full dimension in the first run of the loop.
Ok, thanks.
Kristian wrote:
also when you do declare your array, invert the loop doing for example: for i = arrayDim1 to 1 step -1
It makes it generate faster because you have already set the full dimension in the first run of the loop.
Did not know this! But hell yes! Makes so much sense!
SenecaDesignLLC wrote:
Kristian wrote:
also when you do declare your array, invert the loop doing for example: for i = arrayDim1 to 1 step -1
It makes it generate faster because you have already set the full dimension in the first run of the loop.
Did not know this! But hell yes! Makes so much sense!
I got that bit of gold directly from Gergely Feher (when I visited GSHQ) while he was advising me on ways to speed up Infinite Openings; it made a massive difference!
Creator of Cadswift's parametric GDL libraries
Creator of Infinite Openings and Component Catalogues
Push the envelope & watch it bend
website: https://cadswift.com.au/
YouTube: https://www.youtube.com/user/CADSwift/playlists
Podolsky
Ace
Interesting. What else he advised in term of speeding up the GDL scripts? Please write it here - we will include it into GDL writing rules for everyone. Maybe just write all these rules in Open Source GDL post?
dushyant
Enthusiast
Podolsky wrote:
... Maybe just write all these rules in Open Source GDL post?
What is 'Open Source GDL'? I thought there was only one GDL (by Graphisoft)

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!