Writing back an array

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2020-08-26
08:18 PM
- last edited on
‎2024-09-09
11:09 AM
by
Doreena Deng
What I want to achieve is to yield an array, in the best case a two-dimensional one, back to GDL.
I know I have to write inside the `InputFromDataFile` function to the GDLRequestResult param.
So far, so good. But how to construct the array?
And how to declare the variable in GDL beforehand? Mind you: The user doesn't know how big the array is!
POSIWID – The Purpose Of a System Is What It Does /// «Furthermore, I consider that Carth... yearly releases must be destroyed»

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2020-08-27 12:43 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2020-08-27 12:16 PM
Kristian wrote:None actually, haha.
what file type are you opening to extra the data?
I need the GDL add-on purely for calculations I can't do in GDL.
So, the add-on gets some input and performs calculations on that, and then shall return a multidimensional array.
To make this extra spicy: I can't determine beforehand what size the array will have.
I know that I could do e.g. a
dim myarray[5]
in GDL, then use
value.AddDouble(123.45)
value.AddDouble(42.0)
...
in the add-on.
But this only fills one dimension, and also I need to initialize the array in GDL with either a fixed size, or
dim myarray[] ! dynamic
myarray[1] = 0.0 ! init cell with value
My consideration right now is to instead use a dict in GDL (needs no init!), which then can be filled with an array in the add-on. But I can't figure out how to setup a dict in the GS c++ style either

By the way: can you explain me what type 'GdlValueRecord' is? What it is that for?
POSIWID – The Purpose Of a System Is What It Does /// «Furthermore, I consider that Carth... yearly releases must be destroyed»
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2020-08-27 02:16 PM
Central Innovation

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2020-08-27 02:21 PM
Ralph wrote:Hi Ralph, thanks for tuning in!
In what context will the GDL add-on be called, e.g. within the parameter script? This is important because you can't really make any parameter changes outside of that scope.
From the 2D script. No parameters need to be changed. The values from the calculation add-on shall be used directly for drawing things

POSIWID – The Purpose Of a System Is What It Does /// «Furthermore, I consider that Carth... yearly releases must be destroyed»
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2020-08-27 04:38 PM
Central Innovation

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2020-08-27 07:37 PM
Ralph wrote:Are you sure that this is the way? I couldn't get it to work in my tests. If there was an empty dynamic array passed to the GDL add-on it refused to return anything.
Could you simply define an empty array in the GDL script
If I try to access the array in GDL again it always says "out of bounds" which means there is nothing in there.

POSIWID – The Purpose Of a System Is What It Does /// «Furthermore, I consider that Carth... yearly releases must be destroyed»

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2020-08-28 07:48 AM
> as Ralph said, declare a dynamic array first in the GDL script, then
> open the data and use loop functions and the INPUT commands to navigate through the data to each value I wish to extract. These values populate the previously declared dynamic array during the INPUT commands. to use the 2D aspect of the dynamic array you have to tell it when to move to the next row, which is what you base the structure of your loop statements on; you can set this based on info you pick up out of the data your are importing.
I am not sure if all this works for what you are doing but hope the logic is somehow applicable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2020-08-28 11:58 AM
runxel wrote:We are eliminating the use of GDL add-ons from our toolset because they cause too many problems for customers. But from previous tools, we did the following in GDL (rough pseudocode):
I couldn't get it to work in my tests. If there was an empty dynamic array passed to the GDL add-on it refused to return anything.
If I try to access the array in GDL again it always says "out of bounds" which means there is nothing in there.![]()
dim incomingValues[] rowCount = 0 colCount = 0 unused = input(presetChannel, "Get_Array_Par", "requiredParameterName", rowCount, colCount, incomingValues)…and the following in the addon (again, rough pseudocode):
GSErr __GDLEXT_CALL InputFromDataFile(Int32 channel, GS::UniString const &recordID, GS::UniString const &fieldID, Int32 inCount, Int32* outCount, GS::Array<GdlValueRecord> &values, GS::Array<GS::UniString> &strings) { //...code to define rows, cols etc here *outCount = rows * cols + 2; values.SetCapacity(*outCount); GdlValueRecord rowRecord, colRecord; rowRecord.SetLong(rows); colRecord.SetLong(cols); values.Push(rowRecord); values.Push(colRecord); for (…however you iterate through your array data) { GdlValueRecord record; switch (…whatever data type…) { case intType: record.SetLong(…int value…); break; case realType: record.SetDouble(…double value…); break; case strType: record.SetString(…next string index…); strings.Push(…string value…); upto++; break; } values.Push(record); } }This is a bit rough, but might point you in the right direction. Depends a lot on what you want to do.
Central Innovation

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2020-08-28 08:00 PM
I read that statement of yours already somewhere here. What is your recommendation for replacement then? A normal add-on that somehow populates an object after reading it's parameters? If that's possible (I guess with ACAPI_​Element_​Change, but how to "auto"-call it?), are there code examples for this? Code examples is something the documentation is lacking a lot.
Regarding your code example:
When I replace GDLRequestResult with GS::Array<GdlValueRecord> the compiling will give me linking errors (LNK2001) in the GDLDev.lib – but not declaring the return value an array isn't what I am after, either. Obviously. 😕
POSIWID – The Purpose Of a System Is What It Does /// «Furthermore, I consider that Carth... yearly releases must be destroyed»