<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Writing back an array in Archicad C++ API</title>
    <link>https://community.graphisoft.com/t5/Archicad-C-API/Writing-back-an-array/m-p/274969#M2969</link>
    <description>&lt;BLOCKQUOTE&gt;Kristian wrote:&lt;BR /&gt;
what file type are you opening to extra the data?
&lt;/BLOCKQUOTE&gt;

None actually, haha.&lt;BR /&gt;
I need the GDL add-on purely for calculations I can't do in GDL.&lt;BR /&gt;
So, the add-on gets some input and performs calculations on that, and then shall return a multidimensional array.&lt;BR /&gt;
To make this extra spicy: I can't determine beforehand what size the array will have.&lt;BR /&gt;
&lt;BR /&gt;
I know that I could do e.g. a &lt;BR /&gt;
dim myarray[5]&lt;BR /&gt;
in GDL, then use &lt;BR /&gt;
value.AddDouble(123.45)&lt;BR /&gt;
value.AddDouble(42.0)&lt;BR /&gt;
...&lt;BR /&gt;
in the add-on.&lt;BR /&gt;
But this only fills one dimension, and also I need to initialize the array in GDL with either a fixed size, or &lt;BR /&gt;
dim myarray[]  ! dynamic&lt;BR /&gt;
myarray[1] = 0.0  ! init cell with value&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
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  &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_redface.gif" style="display : inline;" /&gt; &lt;BR /&gt;
&lt;BR /&gt;
By the way: can you explain me what type 'GdlValueRecord' is? What it is that for?</description>
    <pubDate>Thu, 27 Aug 2020 10:16:39 GMT</pubDate>
    <dc:creator>runxel</dc:creator>
    <dc:date>2020-08-27T10:16:39Z</dc:date>
    <item>
      <title>Writing back an array</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Writing-back-an-array/m-p/274967#M2967</link>
      <description>&lt;DIV class="actalk-migrated-content"&gt;I'm working on a GDL add-on (you know, the thing you call with "open("NAME", "", ...)").&lt;BR /&gt;What I want to achieve is to yield an array, in the best case a two-dimensional one, back to GDL.&lt;BR /&gt;&lt;BR /&gt;I know I have to write inside the `InputFromDataFile` function to the GDLRequestResult param.&lt;BR /&gt;So far, so good. But how to construct the array?&lt;BR /&gt;And how to declare the variable in GDL beforehand? Mind you: The user doesn't know how big the array is!&lt;/DIV&gt;</description>
      <pubDate>Mon, 09 Sep 2024 09:09:10 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Writing-back-an-array/m-p/274967#M2967</guid>
      <dc:creator>runxel</dc:creator>
      <dc:date>2024-09-09T09:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: Writing back an array</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Writing-back-an-array/m-p/274968#M2968</link>
      <description>what file type are you opening to extra the data?</description>
      <pubDate>Wed, 26 Aug 2020 22:43:34 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Writing-back-an-array/m-p/274968#M2968</guid>
      <dc:creator>Kristian Bursell</dc:creator>
      <dc:date>2020-08-26T22:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: Writing back an array</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Writing-back-an-array/m-p/274969#M2969</link>
      <description>&lt;BLOCKQUOTE&gt;Kristian wrote:&lt;BR /&gt;
what file type are you opening to extra the data?
&lt;/BLOCKQUOTE&gt;

None actually, haha.&lt;BR /&gt;
I need the GDL add-on purely for calculations I can't do in GDL.&lt;BR /&gt;
So, the add-on gets some input and performs calculations on that, and then shall return a multidimensional array.&lt;BR /&gt;
To make this extra spicy: I can't determine beforehand what size the array will have.&lt;BR /&gt;
&lt;BR /&gt;
I know that I could do e.g. a &lt;BR /&gt;
dim myarray[5]&lt;BR /&gt;
in GDL, then use &lt;BR /&gt;
value.AddDouble(123.45)&lt;BR /&gt;
value.AddDouble(42.0)&lt;BR /&gt;
...&lt;BR /&gt;
in the add-on.&lt;BR /&gt;
But this only fills one dimension, and also I need to initialize the array in GDL with either a fixed size, or &lt;BR /&gt;
dim myarray[]  ! dynamic&lt;BR /&gt;
myarray[1] = 0.0  ! init cell with value&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
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  &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_redface.gif" style="display : inline;" /&gt; &lt;BR /&gt;
&lt;BR /&gt;
By the way: can you explain me what type 'GdlValueRecord' is? What it is that for?</description>
      <pubDate>Thu, 27 Aug 2020 10:16:39 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Writing-back-an-array/m-p/274969#M2969</guid>
      <dc:creator>runxel</dc:creator>
      <dc:date>2020-08-27T10:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: Writing back an array</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Writing-back-an-array/m-p/274970#M2970</link>
      <description>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.</description>
      <pubDate>Thu, 27 Aug 2020 12:16:09 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Writing-back-an-array/m-p/274970#M2970</guid>
      <dc:creator>Ralph Wessel</dc:creator>
      <dc:date>2020-08-27T12:16:09Z</dc:date>
    </item>
    <item>
      <title>Re: Writing back an array</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Writing-back-an-array/m-p/274971#M2971</link>
      <description>&lt;BLOCKQUOTE&gt;Ralph wrote:&lt;BR /&gt;
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.
&lt;/BLOCKQUOTE&gt;

Hi Ralph, thanks for tuning in!&lt;BR /&gt;
From the 2D script. No parameters need to be changed. The values from the calculation add-on shall be used directly for drawing things &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_smile.gif" style="display : inline;" /&gt;</description>
      <pubDate>Thu, 27 Aug 2020 12:21:06 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Writing-back-an-array/m-p/274971#M2971</guid>
      <dc:creator>runxel</dc:creator>
      <dc:date>2020-08-27T12:21:06Z</dc:date>
    </item>
    <item>
      <title>Re: Writing back an array</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Writing-back-an-array/m-p/274972#M2972</link>
      <description>Could you simply define an empty array and 2 variables for the number of rows/columns in the GDL script, then pass those to the GDL add-on? The GDL add-on adds the rows/columns to the result and the list of array values. The GDL script can then unpack the returned array as required using the returned row/column count.</description>
      <pubDate>Thu, 27 Aug 2020 14:38:33 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Writing-back-an-array/m-p/274972#M2972</guid>
      <dc:creator>Ralph Wessel</dc:creator>
      <dc:date>2020-08-27T14:38:33Z</dc:date>
    </item>
    <item>
      <title>Re: Writing back an array</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Writing-back-an-array/m-p/274973#M2973</link>
      <description>&lt;BLOCKQUOTE&gt;Ralph wrote:&lt;BR /&gt;
Could you simply define an empty array in the GDL script
&lt;/BLOCKQUOTE&gt;

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.&lt;BR /&gt;
If I try to access the array in GDL again it always says "out of bounds" which means there is nothing in there.  &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_confused.gif" style="display : inline;" /&gt;</description>
      <pubDate>Thu, 27 Aug 2020 17:37:39 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Writing-back-an-array/m-p/274973#M2973</guid>
      <dc:creator>runxel</dc:creator>
      <dc:date>2020-08-27T17:37:39Z</dc:date>
    </item>
    <item>
      <title>Re: Writing back an array</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Writing-back-an-array/m-p/274974#M2974</link>
      <description>I don't know exactly how to achieve what you want as i don't know the structure of the resulting data/array you are working with. However, with all my data extractions into an array (GDL XML Extension and earlier GDL Text I/O Add-on) I always have to;&lt;BR /&gt;
&amp;gt; as Ralph said, declare a dynamic array first in the GDL script, then&lt;BR /&gt;
&amp;gt; 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.&lt;BR /&gt;
&lt;BR /&gt;
I am not sure if all this works for what you are doing but hope the logic is somehow applicable.</description>
      <pubDate>Fri, 28 Aug 2020 05:48:38 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Writing-back-an-array/m-p/274974#M2974</guid>
      <dc:creator>Kristian Bursell</dc:creator>
      <dc:date>2020-08-28T05:48:38Z</dc:date>
    </item>
    <item>
      <title>Re: Writing back an array</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Writing-back-an-array/m-p/274975#M2975</link>
      <description>&lt;BLOCKQUOTE&gt;runxel wrote:&lt;BR /&gt; 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.&lt;BR /&gt;
If I try to access the array in GDL again it always says "out of bounds" which means there is nothing in there.  &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_confused.gif" style="display : inline;" /&gt;
&lt;/BLOCKQUOTE&gt;
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):&lt;PRE&gt;dim incomingValues[]
rowCount = 0
colCount = 0
unused = input(presetChannel, "Get_Array_Par", "requiredParameterName", rowCount, colCount, incomingValues)&lt;/PRE&gt;
…and the following in the addon (again, rough pseudocode):&lt;PRE&gt;GSErr __GDLEXT_CALL InputFromDataFile(Int32 channel, GS::UniString const &amp;amp;recordID, GS::UniString const &amp;amp;fieldID, Int32 inCount, Int32* outCount, GS::Array&amp;lt;GdlValueRecord&amp;gt; &amp;amp;values, GS::Array&amp;lt;GS::UniString&amp;gt; &amp;amp;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);	
	}
}&lt;/PRE&gt;
This is a bit rough, but might point you in the right direction. Depends a lot on what you want to do.</description>
      <pubDate>Fri, 28 Aug 2020 09:58:54 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Writing-back-an-array/m-p/274975#M2975</guid>
      <dc:creator>Ralph Wessel</dc:creator>
      <dc:date>2020-08-28T09:58:54Z</dc:date>
    </item>
    <item>
      <title>Re: Writing back an array</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Writing-back-an-array/m-p/274976#M2976</link>
      <description>Thanks a lot to both of you, and especially to you, Ralph, for finally some code!&lt;BR /&gt;
&lt;BR /&gt;
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.&lt;BR /&gt;
&lt;BR /&gt;
Regarding your code example:&lt;BR /&gt;
When I replace GDLRequestResult with GS::Array&amp;lt;GdlValueRecord&amp;gt; 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.  &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;</description>
      <pubDate>Fri, 28 Aug 2020 18:00:38 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Writing-back-an-array/m-p/274976#M2976</guid>
      <dc:creator>runxel</dc:creator>
      <dc:date>2020-08-28T18:00:38Z</dc:date>
    </item>
    <item>
      <title>Re: Writing back an array</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Writing-back-an-array/m-p/274977#M2977</link>
      <description>&lt;BLOCKQUOTE&gt;runxel wrote:&lt;BR /&gt;
&lt;BR /&gt;
Regarding your code example:&lt;BR /&gt;
When I replace GDLRequestResult with GS::Array&amp;lt;GdlValueRecord&amp;gt; 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.  :/
&lt;/BLOCKQUOTE&gt;

Any thoughts on that?</description>
      <pubDate>Fri, 11 Sep 2020 14:06:28 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Writing-back-an-array/m-p/274977#M2977</guid>
      <dc:creator>runxel</dc:creator>
      <dc:date>2020-09-11T14:06:28Z</dc:date>
    </item>
  </channel>
</rss>

