<?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 Library Part - array - GSHandle in Archicad C++ API</title>
    <link>https://community.graphisoft.com/t5/Archicad-C-API/Library-Part-array-GSHandle/m-p/261821#M4996</link>
    <description>&lt;DIV class="actalk-migrated-content"&gt;Hello there.&lt;BR /&gt;&lt;BR /&gt;I have been trying to create library parts using the C++ API. However, I have encountered a problem when creating parameters for said library parts. &lt;BR /&gt;&lt;BR /&gt;I can add parameters that are NOT arrays, using the different types (APIParT_Integer, etc...).&lt;BR /&gt;&lt;BR /&gt;However, when I try to create parameters that are arrays, I do not seem to be handling the value.array correctly (GSHandle).&lt;BR /&gt;&lt;BR /&gt;I'm trying to allocate memory for it, but my add-on keeps crashing. &lt;BR /&gt;&lt;BR /&gt;Here is an excerpt of the code that is causing problems:&lt;BR /&gt;
&lt;PRE&gt;//...

(*addPars)&lt;I&gt;.typeMod = 2;

(*addPars)&lt;I&gt;.typeID = APIParT_Integer;
(*addPars)&lt;I&gt;.dim1 = 5;
(*addPars)&lt;I&gt;.dim2 = 1;

(*addPars)&lt;I&gt;.value.array = BMAllocateHandle(sizeof(GSHandle), ALLOCATE_CLEAR, 0);
*(*addPars)&lt;I&gt;.value.array = BMAllocatePtr(5 * sizeof(int), ALLOCATE_CLEAR, 0);

if ((*addPars)&lt;I&gt;.value.array == NULL || *(*addPars)&lt;I&gt;.value.array == NULL){
  ACAPI_WriteReport("NOPE!", true);
  return;
}

for (int j = 0; j &amp;lt; 5; j++){
  (int)((int *)*(*addPars)&lt;I&gt;.value.array) = msg.intarrays(intArrayCounter).lst(j);
}

//...
&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;
My question is how to correctly work with the array of the parameters.&lt;BR /&gt;&lt;BR /&gt;Can someone help?&lt;BR /&gt;&lt;BR /&gt;Thanks in advance, &lt;BR /&gt;Xylios&lt;/DIV&gt;</description>
    <pubDate>Wed, 12 Jul 2023 19:11:00 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2023-07-12T19:11:00Z</dc:date>
    <item>
      <title>Library Part - array - GSHandle</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Library-Part-array-GSHandle/m-p/261821#M4996</link>
      <description>&lt;DIV class="actalk-migrated-content"&gt;Hello there.&lt;BR /&gt;&lt;BR /&gt;I have been trying to create library parts using the C++ API. However, I have encountered a problem when creating parameters for said library parts. &lt;BR /&gt;&lt;BR /&gt;I can add parameters that are NOT arrays, using the different types (APIParT_Integer, etc...).&lt;BR /&gt;&lt;BR /&gt;However, when I try to create parameters that are arrays, I do not seem to be handling the value.array correctly (GSHandle).&lt;BR /&gt;&lt;BR /&gt;I'm trying to allocate memory for it, but my add-on keeps crashing. &lt;BR /&gt;&lt;BR /&gt;Here is an excerpt of the code that is causing problems:&lt;BR /&gt;
&lt;PRE&gt;//...

(*addPars)&lt;I&gt;.typeMod = 2;

(*addPars)&lt;I&gt;.typeID = APIParT_Integer;
(*addPars)&lt;I&gt;.dim1 = 5;
(*addPars)&lt;I&gt;.dim2 = 1;

(*addPars)&lt;I&gt;.value.array = BMAllocateHandle(sizeof(GSHandle), ALLOCATE_CLEAR, 0);
*(*addPars)&lt;I&gt;.value.array = BMAllocatePtr(5 * sizeof(int), ALLOCATE_CLEAR, 0);

if ((*addPars)&lt;I&gt;.value.array == NULL || *(*addPars)&lt;I&gt;.value.array == NULL){
  ACAPI_WriteReport("NOPE!", true);
  return;
}

for (int j = 0; j &amp;lt; 5; j++){
  (int)((int *)*(*addPars)&lt;I&gt;.value.array) = msg.intarrays(intArrayCounter).lst(j);
}

//...
&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;
My question is how to correctly work with the array of the parameters.&lt;BR /&gt;&lt;BR /&gt;Can someone help?&lt;BR /&gt;&lt;BR /&gt;Thanks in advance, &lt;BR /&gt;Xylios&lt;/DIV&gt;</description>
      <pubDate>Wed, 12 Jul 2023 19:11:00 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Library-Part-array-GSHandle/m-p/261821#M4996</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-07-12T19:11:00Z</dc:date>
    </item>
    <item>
      <title>Re: Library Part - array - GSHandle</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Library-Part-array-GSHandle/m-p/261822#M4997</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
Did you look at the \Examples\LibPart_Test\Src\LibPart_Test.cpp in the SDK samples folder ?&lt;BR /&gt;
&lt;BR /&gt;
There is an example for creating lib parts.&lt;BR /&gt;
&lt;BR /&gt;
In the method "Do_CreateLibraryPart" there is a code for creating simple parameters and also array parameters.&lt;BR /&gt;
&lt;BR /&gt;
Here is a part of the code but the best is to look at the complete sample :&lt;BR /&gt;

&lt;PRE&gt;			pAddPar = &amp;amp;(*addPars)[3];
			pAddPar-&amp;gt;typeID = APIParT_RealNum;
			pAddPar-&amp;gt;typeMod = API_ParArray;
			pAddPar-&amp;gt;dim1 = 3;
			pAddPar-&amp;gt;dim2 = 4;
			CHTruncate ("matrix", pAddPar-&amp;gt;name, sizeof (pAddPar-&amp;gt;name));
			GS::ucscpy (pAddPar-&amp;gt;uDescname, L("Array parameter with real numbers"));
			pAddPar-&amp;gt;value.array = BMAllocateHandle (pAddPar-&amp;gt;dim1 * pAddPar-&amp;gt;dim2 * sizeof (double), ALLOCATE_CLEAR, 0);
			double** arrHdl = reinterpret_cast&amp;lt;double**&amp;gt;(pAddPar-&amp;gt;value.array);
			for (Int32 k = 0; k &amp;lt; pAddPar-&amp;gt;dim1; k++)
				for (Int32 j = 0; j &amp;lt; pAddPar-&amp;gt;dim2; j++)
					(*arrHdl)[k * pAddPar-&amp;gt;dim2 + j] = (k == j ? 1.1 : 0.0);
&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Feb 2016 17:09:15 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Library-Part-array-GSHandle/m-p/261822#M4997</guid>
      <dc:creator>gehairing</dc:creator>
      <dc:date>2016-02-23T17:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: Library Part - array - GSHandle</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Library-Part-array-GSHandle/m-p/261823#M4998</link>
      <description>Hey.&lt;BR /&gt;
&lt;BR /&gt;
Thank you for the reply. I have looked at the LibPart_Test, but it was from the ArchiCAD 18 DevKit (the one I'm currently using) and it did not had the array example. I assume that the one you are using is the one from the ArchiCAD 19 DevKit.&lt;BR /&gt;
&lt;BR /&gt;
I will try to get the one from the most recent DevKit, thank you.</description>
      <pubDate>Tue, 23 Feb 2016 17:26:10 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Library-Part-array-GSHandle/m-p/261823#M4998</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-02-23T17:26:10Z</dc:date>
    </item>
    <item>
      <title>Re: Library Part - array - GSHandle</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Library-Part-array-GSHandle/m-p/261824#M4999</link>
      <description>Hey.&lt;BR /&gt;
&lt;BR /&gt;
I have successfully created arrays of various types (such as APIParT_RealNum, APIParT_Integer ...)  using the example you mentioned. &lt;BR /&gt;
&lt;BR /&gt;
However, I have found another obstacle, I cannot seem to be able to create arrays of type string (APIParT_CString).&lt;BR /&gt;
&lt;BR /&gt;
Anyone can help me with that? &lt;BR /&gt;
&lt;BR /&gt;
I have tried to allocate space for char or double, and do the respective cast, but had no luck.&lt;BR /&gt;

&lt;PRE&gt;(*addPars)&lt;I&gt;.value.array = BMAllocateHandle(4 * sizeof(char), ALLOCATE_CLEAR, 0);
char** arrHdl = reinterpret_cast&amp;lt;char**&amp;gt;((*addPars)&lt;I&gt;.value.array);

//(*addPars)&lt;I&gt;.value.array = BMAllocateHandle(4 * sizeof(double), ALLOCATE_CLEAR, 0);
//double** arrHdl = reinterpret_cast&amp;lt;double**&amp;gt;((*addPars)&lt;I&gt;.value.array);

(*arrHdl)[0] = 'a';
(*arrHdl)[1] = '\0';
(*arrHdl)[2] = 'b';
(*arrHdl)[3] = '\0';
&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;

&lt;BR /&gt;
&lt;B&gt;UPDATE:&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
I have found the solution:&lt;BR /&gt;

&lt;PRE&gt;//actualSize is the number of characters of every strings you want added plus the number of said strings
//ex: you want two strings "abc" and "st", the value of actualSize will be 3 + 2 + 2 = 7
//to note that the dim1 will still be the number of strings you want, in this example, 2. But you will allocate space for every character plus every separator '\0'.
//the final value of the array will be "abc\0st\0"
int numberOfStrings = 2;
(*addPars)&lt;I&gt;.dim1 = numberOfStrings;
(*addPars)&lt;I&gt;.dim2 = 1
(*addPars)&lt;I&gt;.value.array = BMAllocateHandle(actualSize * (*addPars)&lt;I&gt;.dim2 * sizeof(GS::uchar_t), ALLOCATE_CLEAR, 0);
GS::uchar_t** arrHdl = reinterpret_cast&amp;lt;GS::uchar_t**&amp;gt;((*addPars)&lt;I&gt;.value.array);
&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;

Hope that this can help anyone with the same problem.&lt;BR /&gt;
&lt;BR /&gt;
Best regards,&lt;BR /&gt;
Xylios</description>
      <pubDate>Wed, 24 Feb 2016 14:44:40 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Library-Part-array-GSHandle/m-p/261824#M4999</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-02-24T14:44:40Z</dc:date>
    </item>
  </channel>
</rss>

