2024-03-13 05:41 PM - last edited on 2024-09-26 01:11 PM by Doreena Deng
HI I have A global object with a parameter xy[16][16]
Now I want to find the easiest way to get the content of xy[5][6].
The only way I actually get a result is:
k=LIBRARYGLOBAL ("glob_obj", "xy", cont_1, cont_2, cont_3,...) where cont_1=xy[1][1], cont_2=xy[1][2], cont_3=xy[1][3]
I have 16 cloums so i guess i'll need to go until ...,cont_15,cont_16,cont_17) to make cont_17 the field xy[2][1] but I havn't tried that.
Is there no more efficient way to "call" the content of a field?
2024-03-13 06:05 PM
Please read this topic:
https://community.graphisoft.com/t5/GDL/LIBRARYGLOBAL-vs-2-dimension-array/m-p/252379#M2866
2024-03-13 06:42 PM
sorry, that comunication doesn't help me. They are talking about calling obejects etc...
2024-03-13 07:22 PM
Read carefully then. The concept is the same!
To quote myself and the GDL manual:
"Requests (and Libraryglobal is also a request) do not handle two-dimensional arrays."
And Kristian shows how to convert it back to a 2D array from a 1D one.
Only difference: You'll need to now the dimensions yourself, the request doesn't return them.
2024-03-13 11:46 PM - last edited on 2024-03-15 03:38 PM by Laszlo Nagy
The entire array has to be read up to the point of the number you wish to get,
either
k=LIBRARYGLOBAL ("glob_obj", "xy", cont_1, cont_2, cont_3,...)
or ..................
use an array function to read all the variables and then reconstruct the array in the new file
I set the array sizes in the global
!!------this bit is just to set some values for this test
for j = 1 to 16
for ii = 1 to 18
xy[ii][j] = ii*100+j
next ii
next j
parameters xy = xy
!!------this bit is just to set some values for this test
!!------this bit measures the size of the array and sets it as variables that can be read
xy_array1 = vardim1(xy)
xy_array2 = vardim2(xy)
parameters xy_array1 = xy_array1
parameters xy_array2 = xy_array2
!!------this bit measures the size of the array and sets it as variables that can be read
then read the array,
you will see that the new array read will only be a 1 dimensional array
so a 1x288 rather than a 18x16 as per the original
!!!----READ THE ARRAY FROM THE LIBRARY GLOBAL INTO A NEW ARRAY "xy_Temp[][]"----!!
dim xy_Temp[][]
!!!___note you can just do a 1 dimensional array at this point
!!!"dim xy_Temp[]"
success0 = LIBRARYGLOBAL ("1-test GLOBAL", "xy", xy_Temp)
success1 = LIBRARYGLOBAL ("1-test GLOBAL", "xy_array1", xy_array1)
success2 = LIBRARYGLOBAL ("1-test GLOBAL", "xy_array2", xy_array2)
!!!!if just reading from the array then you could just use
co_ordinate1 = (xy_array2)*(6-1)+5
text2 0,1, vardim1(xy_Temp)
text2 0,2, vardim2(xy_Temp)
text2 0,3,xy_array1
text2 0,4,xy_array2
text2 0,5,xy_Temp[1][co_ordinate1]
!!!----CONVERT 1 DIMENSIONAL ARRAY BACK TO 2 DIMENSIONAL ARRAY----!!
dim xy[][]
for j = 1 to xy_array1
for i = 1 to xy_array2
co_ordinate = (j-1)*xy_array2+i
xy[j][i] = xy_Temp[1][co_ordinate]
next i
next j
text2 0,7,xy[6][5]
parameters xy = xy
I hope this helps
P.S.
if you don't want to convert it back to an array you only need :
dim xy_Temp[]
success0 = LIBRARYGLOBAL ("1-test GLOBAL", "xy", xy_Temp)
success2 = LIBRARYGLOBAL ("1-test GLOBAL", "xy_array2", xy_array2)
co_ordinate1 = (xy_array2)*(6-1)+5
text2 0,5,xy_Temp[co_ordinate1]
and if the size of the array is always know(it wont change in the future) then you can replace the xy_array2 part with the fixed number.
2024-04-18 10:21 AM
Thank you very much, I'll try that as soon as I have time.