<?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: How to set values for array value in Object? in Archicad C++ API</title>
    <link>https://community.graphisoft.com/t5/Archicad-C-API/How-to-set-values-for-array-value-in-Object/m-p/570908#M8725</link>
    <description>&lt;P&gt;There are a few issues with your code.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;I think &lt;STRONG&gt;ACAPI_Goodies (APIAny_CloseParametersID)&lt;/STRONG&gt; is unnecessary here (because you don't use all of the other &lt;STRONG&gt;APIAny_OpenParametersID&lt;/STRONG&gt; etc.) Better to leave it out if you don't do the other stuff as well.&lt;/LI&gt;
&lt;LI&gt;Don't kill the "&lt;STRONG&gt;arrHdl&lt;/STRONG&gt;" handle after you just changed it! It references the data in the memo which you need to create the element.&lt;/LI&gt;
&lt;LI&gt;It's still not clear if the dimensions you want and the dimensions of the actual allocated array parameter match.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Here's your code changed so it creates an object if you have a library part with an existing parameter called "&lt;STRONG&gt;matrix_area&lt;/STRONG&gt;".&lt;/P&gt;
&lt;P&gt;I'm using references instead of handles and pointers in some places because it's easier for me to read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;void Create ()
{
	API_Element element;
	API_ElementMemo memo;
	API_LibPart libPart;

	BNZeroMemory (&amp;amp;element, sizeof (API_Element));
	BNZeroMemory (&amp;amp;libPart, sizeof (API_LibPart));
	BNZeroMemory (&amp;amp;memo, sizeof (API_ElementMemo));
	BNClear (element);
	BNClear (memo);

	GSErrCode err;

	libPart.typeID = APILib_ObjectID;

	GS::ucscpy (libPart.docu_UName, L ("test"));

	err = ACAPI_LibPart_Search (&amp;amp;libPart, false);

	if (err == APIERR_BADNAME) {
		ACAPI_WriteReport ("Khong tim thay thu vien", false);
	}

	element.header.type = API_ObjectID;
	err = ACAPI_Element_GetDefaults (&amp;amp;element, &amp;amp;memo);
	if (err != NoError) {
		ACAPI_WriteReport ("ACAPI_Element_GetDefaults has failed with error code %ld!", true, err);
		ACAPI_DisposeElemMemoHdls (&amp;amp;memo);
		return;
	}

	double				aa = 0, bb = 0;
	Int32				addParNum;
	ACAPI_LibPart_GetParams (libPart.index, &amp;amp;aa, &amp;amp;bb, &amp;amp;addParNum, &amp;amp;memo.params);
	element.object.libInd = libPart.index;

	UInt32 totalParams = BMGetHandleSize((GSConstHandle)memo.params) / sizeof(API_AddParType);

	int num_row = 8;
	int num_col = 4;
	for (UInt32 i = 0; i &amp;lt; totalParams; i++) {
		if ((*memo.params)[i].name == (GS::UniString)"matrix_area")
		{
			auto&amp;amp; currentParam = (*memo.params)[i];
			currentParam.dim1 = num_row;
			currentParam.dim2 = num_col;

			currentParam.value.array =
				BMReallocHandle (currentParam.value.array,
					num_row * num_col * sizeof (double),
					REALLOC_FULLCLEAR, 0);

			auto paramArray = reinterpret_cast&amp;lt;double*&amp;gt;(*currentParam.value.array);
			for (Int32 k = 0; k &amp;lt; num_row; k++)
				for (Int32 j = 0; j &amp;lt; num_col; j++)
					paramArray[k * num_col + j] = 11.0;

			// DON'T kill handle here already! We still need it to create the element!
			// It's just referenced through 'memo' there.
		}
	}

	err = ACAPI_Element_Create (&amp;amp;element, &amp;amp;memo);

	ACAPI_DisposeElemMemoHdls (&amp;amp;memo);
}
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you can't get it to work, please provide more details of what is not working specifically (error codes, expected vs. actual behavior or crashes).&lt;/P&gt;
&lt;P&gt;Hope that helps!&lt;BR /&gt;&lt;BR /&gt;Bernd&lt;/P&gt;</description>
    <pubDate>Sun, 15 Oct 2023 22:57:55 GMT</pubDate>
    <dc:creator>BerndSchwarzenbacher</dc:creator>
    <dc:date>2023-10-15T22:57:55Z</dc:date>
    <item>
      <title>How to set values for array value in Object?</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/How-to-set-values-for-array-value-in-Object/m-p/570648#M8697</link>
      <description>&lt;P&gt;HI guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have an object tool loaded into ArchiCAD and it has a parameter which is an array value. Now I want to get it and set a new value for it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I did it like this as in&amp;nbsp;LibPart_Test:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;UInt32 totalParams1 = BMGetHandleSize((GSConstHandle)memo.params);

	UInt32 totalParams = BMGetHandleSize((GSConstHandle)memo.params) / sizeof(API_AddParType);

	for (UInt32 i = 0; i &amp;lt; totalParams; i++) {

		if ((*memo.params)[i].name == (GS::UniString)"matrix_area")
		{
			(*memo.params)[i].value.array = BMAllocateHandle((*memo.params)[i].dim1 * (*memo.params)[i].dim2 * sizeof(double), ALLOCATE_CLEAR, 0);

			double** arrHdl = reinterpret_cast&amp;lt;double**&amp;gt;((*memo.params)[i].value.array);

			for (Int32 k = 0; k &amp;lt; (*memo.params)[i].dim1; k++)
				for (Int32 j = 0; j &amp;lt; (*memo.params)[i].dim2; j++)
					(*arrHdl)[k * (*memo.params)[i].dim2 + j] = (k == j ? 1.1 : 0.0);

		}
	}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But It's not right.&lt;/P&gt;
&lt;P&gt;Can you help me know where I'm wrong?&lt;/P&gt;
&lt;P&gt;Thank you very much.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2024 12:27:53 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/How-to-set-values-for-array-value-in-Object/m-p/570648#M8697</guid>
      <dc:creator>Tran Thanh Lo</dc:creator>
      <dc:date>2024-09-16T12:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to set values for array value in Object?</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/How-to-set-values-for-array-value-in-Object/m-p/570708#M8705</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;There could be a lot of different issues, depending mostly on where you get the memo from.&lt;BR /&gt;So please specify what you do before this code with the memo structure and also what specifically is not working.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One of my guesses is, that one of your dim1 or dim2 are maybe 0.&lt;BR /&gt;&lt;BR /&gt;Best,&lt;/P&gt;
&lt;P&gt;Bernd&lt;/P&gt;</description>
      <pubDate>Fri, 13 Oct 2023 05:58:02 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/How-to-set-values-for-array-value-in-Object/m-p/570708#M8705</guid>
      <dc:creator>BerndSchwarzenbacher</dc:creator>
      <dc:date>2023-10-13T05:58:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to set values for array value in Object?</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/How-to-set-values-for-array-value-in-Object/m-p/570750#M8711</link>
      <description>&lt;P&gt;Hi bschwb,&lt;/P&gt;&lt;P&gt;Thank you for responding, I get the memo like this. And my dim1 and dim2 have a value.&lt;/P&gt;&lt;P&gt;Can you help me tell me where I'm wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;API_Element element;
	API_ElementMemo memo;
	API_LibPart libPart;

	BNZeroMemory(&amp;amp;element, sizeof(API_Element));
	BNZeroMemory(&amp;amp;libPart, sizeof(API_LibPart));
	BNZeroMemory(&amp;amp;memo, sizeof(API_ElementMemo));
	BNClear(element);
	BNClear(memo);

	GSErrCode			err;

	BNZeroMemory(&amp;amp;libPart, sizeof(API_LibPart));

	libPart.typeID = APILib_ObjectID;

	CHCopyC("{4FD10D67-2F29-4844-A65A-6597589B0CB5}-{3BC96B79-9E97-42A3-969C-600334C0D18D}", libPart.parentUnID);
	GS::ucscpy(libPart.docu_UName, L("Schedule1"));

	err = ACAPI_LibPart_Search(&amp;amp;libPart, false);

	if (err == APIERR_BADNAME)
		ACAPI_WriteReport("Khong tim thay thu vien", false);

	element.header.type = API_ObjectID;
	err = ACAPI_Element_GetDefaults(&amp;amp;element, &amp;amp;memo);
	if (err != NoError) {
		ACAPI_WriteReport("ACAPI_Element_GetDefaults has failed with error code %ld!", true, err);
		ACAPI_DisposeElemMemoHdls(&amp;amp;memo);
		return;
	}

	double				aa = 0, bb = 0;
	Int32				addParNum;
	ACAPI_LibPart_GetParams(libPart.index, &amp;amp;aa, &amp;amp;bb, &amp;amp;addParNum, &amp;amp;memo.params);

	element.object.libInd = libPart.index;
	


	err = ACAPI_Goodies(APIAny_CloseParametersID);&lt;/LI-CODE&gt;&lt;P&gt;And I change to this but it's still not right.&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;UInt32 totalParams1 = BMGetHandleSize((GSConstHandle)memo.params);


	UInt32 totalParams = BMGetHandleSize((GSConstHandle)memo.params) / sizeof(API_AddParType);

	int num_row = 8;
	int num_col = 4;
	for (UInt32 i = 0; i &amp;lt; totalParams; i++) {
		if ((*memo.params)[i].name == (GS::UniString)"matrix_area")
		{
			API_AddParType* pAddPar = &amp;amp;(*memo.params)[i];

			double** arrHdl = reinterpret_cast&amp;lt;double**&amp;gt;(pAddPar-&amp;gt;value.array);
			for (Int32 k = 0; k &amp;lt; num_row; k++)
				for (Int32 j = 0; j &amp;lt; num_col; j++)
					(*arrHdl)[k * num_col + j] = 11;

			BMKillHandle(reinterpret_cast&amp;lt;GSHandle*&amp;gt;(&amp;amp;arrHdl));
		}
	}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Oct 2023 16:41:14 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/How-to-set-values-for-array-value-in-Object/m-p/570750#M8711</guid>
      <dc:creator>Tran Thanh Lo</dc:creator>
      <dc:date>2023-10-13T16:41:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to set values for array value in Object?</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/How-to-set-values-for-array-value-in-Object/m-p/570908#M8725</link>
      <description>&lt;P&gt;There are a few issues with your code.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;I think &lt;STRONG&gt;ACAPI_Goodies (APIAny_CloseParametersID)&lt;/STRONG&gt; is unnecessary here (because you don't use all of the other &lt;STRONG&gt;APIAny_OpenParametersID&lt;/STRONG&gt; etc.) Better to leave it out if you don't do the other stuff as well.&lt;/LI&gt;
&lt;LI&gt;Don't kill the "&lt;STRONG&gt;arrHdl&lt;/STRONG&gt;" handle after you just changed it! It references the data in the memo which you need to create the element.&lt;/LI&gt;
&lt;LI&gt;It's still not clear if the dimensions you want and the dimensions of the actual allocated array parameter match.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Here's your code changed so it creates an object if you have a library part with an existing parameter called "&lt;STRONG&gt;matrix_area&lt;/STRONG&gt;".&lt;/P&gt;
&lt;P&gt;I'm using references instead of handles and pointers in some places because it's easier for me to read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;void Create ()
{
	API_Element element;
	API_ElementMemo memo;
	API_LibPart libPart;

	BNZeroMemory (&amp;amp;element, sizeof (API_Element));
	BNZeroMemory (&amp;amp;libPart, sizeof (API_LibPart));
	BNZeroMemory (&amp;amp;memo, sizeof (API_ElementMemo));
	BNClear (element);
	BNClear (memo);

	GSErrCode err;

	libPart.typeID = APILib_ObjectID;

	GS::ucscpy (libPart.docu_UName, L ("test"));

	err = ACAPI_LibPart_Search (&amp;amp;libPart, false);

	if (err == APIERR_BADNAME) {
		ACAPI_WriteReport ("Khong tim thay thu vien", false);
	}

	element.header.type = API_ObjectID;
	err = ACAPI_Element_GetDefaults (&amp;amp;element, &amp;amp;memo);
	if (err != NoError) {
		ACAPI_WriteReport ("ACAPI_Element_GetDefaults has failed with error code %ld!", true, err);
		ACAPI_DisposeElemMemoHdls (&amp;amp;memo);
		return;
	}

	double				aa = 0, bb = 0;
	Int32				addParNum;
	ACAPI_LibPart_GetParams (libPart.index, &amp;amp;aa, &amp;amp;bb, &amp;amp;addParNum, &amp;amp;memo.params);
	element.object.libInd = libPart.index;

	UInt32 totalParams = BMGetHandleSize((GSConstHandle)memo.params) / sizeof(API_AddParType);

	int num_row = 8;
	int num_col = 4;
	for (UInt32 i = 0; i &amp;lt; totalParams; i++) {
		if ((*memo.params)[i].name == (GS::UniString)"matrix_area")
		{
			auto&amp;amp; currentParam = (*memo.params)[i];
			currentParam.dim1 = num_row;
			currentParam.dim2 = num_col;

			currentParam.value.array =
				BMReallocHandle (currentParam.value.array,
					num_row * num_col * sizeof (double),
					REALLOC_FULLCLEAR, 0);

			auto paramArray = reinterpret_cast&amp;lt;double*&amp;gt;(*currentParam.value.array);
			for (Int32 k = 0; k &amp;lt; num_row; k++)
				for (Int32 j = 0; j &amp;lt; num_col; j++)
					paramArray[k * num_col + j] = 11.0;

			// DON'T kill handle here already! We still need it to create the element!
			// It's just referenced through 'memo' there.
		}
	}

	err = ACAPI_Element_Create (&amp;amp;element, &amp;amp;memo);

	ACAPI_DisposeElemMemoHdls (&amp;amp;memo);
}
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you can't get it to work, please provide more details of what is not working specifically (error codes, expected vs. actual behavior or crashes).&lt;/P&gt;
&lt;P&gt;Hope that helps!&lt;BR /&gt;&lt;BR /&gt;Bernd&lt;/P&gt;</description>
      <pubDate>Sun, 15 Oct 2023 22:57:55 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/How-to-set-values-for-array-value-in-Object/m-p/570908#M8725</guid>
      <dc:creator>BerndSchwarzenbacher</dc:creator>
      <dc:date>2023-10-15T22:57:55Z</dc:date>
    </item>
  </channel>
</rss>

