<?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: ACAPI_LibPart_UpdateSection error in Archicad C++ API</title>
    <link>https://community.graphisoft.com/t5/Archicad-C-API/ACAPI-LibPart-UpdateSection-error/m-p/308159#M1764</link>
    <description>&lt;P&gt;Hello&lt;BR /&gt;&lt;BR /&gt;I have tried a simplified code like the one below here.&lt;BR /&gt;The error is exactly the same.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;The solution is probably something very simple...but i can't see what&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;// Experimental function for addPar updates
void BACDownload::TestParameterUpdates(API_LibPart&amp;amp; libPart)
{
	// Get the library part
	GSErrCode err = ACAPI_LibPart_Get(&amp;amp;libPart);
	if (err == NoError)
	{
		if (libPart.location != NULL)
		{
			delete libPart.location;
			libPart.location = NULL;
		}
	}

	// Define a parameter section
	API_LibPartSection section;
	BNZeroMemory(&amp;amp;section, sizeof(API_LibPartSection));
	section.sectType = API_SectParamDef;

	// Get parameter section
	GSHandle sectionHdl = NULL;
	err = ACAPI_LibPart_GetSection(libPart.index, &amp;amp;section, &amp;amp;sectionHdl, NULL);
	if (err) return;

	// Get current parameters
	double a, b;
	Int32 addParNum, i;
	API_AddParType** addPars;
	err = ACAPI_LibPart_GetParams(libPart.index, &amp;amp;a, &amp;amp;b, &amp;amp;addParNum, &amp;amp;addPars);
	if (err) return;
	
	// ..
	// Do nothing with the parameters
	// ..

	// Build a section handle with all parameters
	GSHandle Sect2DDrawHdl = NULL;
	err = ACAPI_LibPart_GetSect_ParamDef(&amp;amp;libPart, addPars, &amp;amp;a, &amp;amp;b, Sect2DDrawHdl, &amp;amp;sectionHdl);

	// Update our section
	err = ACAPI_LibPart_UpdateSection(libPart.index, &amp;amp;section, sectionHdl, NULL);
	// NOTE : Here above i get and error : APIERR_BADPARS :	-2130313112 : The passed parameters are inconsistent.

	BMKillHandle(&amp;amp;sectionHdl);
	ACAPI_DisposeAddParHdl(&amp;amp;addPars);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 04 Oct 2021 06:13:34 GMT</pubDate>
    <dc:creator>gehairing</dc:creator>
    <dc:date>2021-10-04T06:13:34Z</dc:date>
    <item>
      <title>ACAPI_LibPart_UpdateSection error</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/ACAPI-LibPart-UpdateSection-error/m-p/307648#M1763</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's a long time i didn't work on an Archicad add-on. It's a pleasure to be back .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have upgraded&amp;nbsp; and enhanced older add-ons i had written for AC 18 to AC 22.&lt;/P&gt;
&lt;P&gt;Now i have a problem i couldn't understand. I have searched &amp;amp; tried other things for days, so i think it's time to ask here. &lt;span class="lia-unicode-emoji" title=":monkey_face:"&gt;🐵&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have an error using the&amp;nbsp;ACAPI_LibPart_UpdateSection. It returns me an APIAPIERR_BADPARS error and i can't find out why. Below is a complete function i use for adding or updating one parameter of a given LibPart.&lt;/P&gt;
&lt;P&gt;Everything run's well until the last call to UpdateSection.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have tried simplifying the code, tried on several ten's of libparts, nothing changes. I have also tried a version where i only do getting the existing parameters and then try to reset exactly the same parameter via the UpdateSection and receive same error.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The library files (.gsm) are copied in the&amp;nbsp;API_SpecFolderID::API_EmbeddedProjectLibraryFolderID. The copies are correct and are usable normally in Archicad 25.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did some essential things changed in the new API (AC25) ?&lt;/P&gt;
&lt;P&gt;Do you see something wrong in this code ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Georges&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The calling code (simplified) :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;// Get the library part
GSErrCode err = ACAPI_LibPart_Get(&amp;amp;libPart);

... other code here

if (libPart.location != NULL)
{
    delete libPart.location;
    libPart.location = NULL;
}

... other code here

AddOrUpdateParameter(libPart, bacParameter);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The function with the problem at the end :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;// Add or replace one parameter in given Library part
void BACDownload::AddOrUpdateParameter(API_LibPart&amp;amp; libPart, BACParameter bacParameter)
{
	GSErrCode err;

	API_AddParType parameter;

	// Manage type
	switch(bacParameter.typeCode)	
	{
	case BACObjectProperty::eDataType::kDTUndefined:
		// We use default string setting if type code is undefined
		SetStringValue(bacParameter.name, bacParameter.value, APIParT_CString, parameter);
		break;
	case BACObjectProperty::eDataType::kDTNumerical:
		SetRealValue(bacParameter.name, ""/*mappingEntry.unitCode*/, bacParameter.value, APIParT_RealNum, parameter);
		break;
	case BACObjectProperty::eDataType::kDTBoolean:
		break;
	case BACObjectProperty::eDataType::kDTString:
		SetStringValue(bacParameter.name, bacParameter.value, APIParT_CString, parameter);
		break;
	default:
		SetStringValue(bacParameter.name, bacParameter.value, APIParT_CString, parameter);
		break;
	};

	// Copy the description name 
	GS::ucscpy(parameter.uDescname, bacParameter.name.ToUStr());

	API_LibPartSection section;
	BNZeroMemory(&amp;amp;section, sizeof(API_LibPartSection));
	section.sectType = API_SectParamDef;

	// Get correct section
	GSHandle sectionHdl = NULL;
	err = ACAPI_LibPart_GetSection(libPart.index, &amp;amp;section, &amp;amp;sectionHdl, NULL);
	if (err) return;

	// Get current parameters
	double a, b;
	Int32 addParNum, i;
	API_AddParType **addPars;
	err = ACAPI_LibPart_GetParams(libPart.index, &amp;amp;a, &amp;amp;b, &amp;amp;addParNum, &amp;amp;addPars);
	if (err) return;

	bool existingParameter = false;

	// Does the parameter exist ?
	for (Int32 i = 0; i &amp;lt; addParNum; i++)
	{
		GS::UniString us = (*addPars)[i].name;
		if (CHCompareASCII((*addPars)[i].name, parameter.name) == 0)
		{
			GS::UniString s1 = (*addPars)[i].uDescname;
			GS::UniString s2 = parameter.uDescname;
			if (s1 == s2)
			{
				// Parameter already exist
				existingParameter = true;
			}
		}
	}

	if (existingParameter)
	{
		// Replace existing parameter

		// Create a new handle by allocating space for all existing parameters
		short nPars = addParNum;
		API_AddParType** newAddPars = reinterpret_cast&amp;lt;API_AddParType**&amp;gt;(BMAllocateHandle(nPars * sizeof(API_AddParType), ALLOCATE_CLEAR, 0));
		if (addPars != NULL)
		{
			// Copy all existing parameter and modify one
			for (i = 0; i &amp;lt; addParNum; i++)
			{

				// Is it the existing one ?
				if (CHCompareASCII((*addPars)[i].name, parameter.name) == 0)
				{
					// Replace it by the new one
					(*newAddPars)[i] = parameter;
				}
				else
				{
					// Recopy the same one
					(*newAddPars)[i] = (*addPars)[i];
				}
			}

			// Build a section handle with all parameters
			GSHandle Sect2DHdl = NULL;
			err = ACAPI_LibPart_GetSect_ParamDef(&amp;amp;libPart, newAddPars, &amp;amp;a, &amp;amp;b, NULL, &amp;amp;sectionHdl);

			BMKillHandle(reinterpret_cast&amp;lt;GSHandle*&amp;gt;(&amp;amp;newAddPars));
		}
	}
	else
	{
		// Add a new parameter

		// Create a new handle by allocating space for all parameters (existing ones and new ones)
		short nPars = addParNum + 1;
		API_AddParType** newAddPars = reinterpret_cast&amp;lt;API_AddParType**&amp;gt;(BMAllocateHandle(nPars * sizeof(API_AddParType), ALLOCATE_CLEAR, 0));
		if (addPars != NULL)
		{
			// Copy all existing parameters
			for (i = 0; i &amp;lt; addParNum; i++)
			{
				API_AddParType* parameter = &amp;amp;(*addPars)[i];
				(*newAddPars)[i] = (*addPars)[i];
			}

			(*newAddPars)[addParNum + 0] = parameter;

			// Build a section handle with all parameters
			GSHandle Sect2DHdl = NULL;
			err = ACAPI_LibPart_GetSect_ParamDef(&amp;amp;libPart, newAddPars, &amp;amp;a, &amp;amp;b, NULL, &amp;amp;sectionHdl);

			BMKillHandle(reinterpret_cast&amp;lt;GSHandle*&amp;gt;(&amp;amp;newAddPars));
		}
	}

	// Update our section
	err = ACAPI_LibPart_UpdateSection(libPart.index, &amp;amp;section, sectionHdl, NULL);
	// NOTE : Here above i get and error : APIERR_BADPARS :	-2130313112 : The passed parameters are inconsistent.

	BMKillHandle(&amp;amp;sectionHdl);
	ACAPI_DisposeAddParHdl(&amp;amp;addPars);
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Oct 2021 18:49:46 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/ACAPI-LibPart-UpdateSection-error/m-p/307648#M1763</guid>
      <dc:creator>gehairing</dc:creator>
      <dc:date>2021-10-05T18:49:46Z</dc:date>
    </item>
    <item>
      <title>Re: ACAPI_LibPart_UpdateSection error</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/ACAPI-LibPart-UpdateSection-error/m-p/308159#M1764</link>
      <description>&lt;P&gt;Hello&lt;BR /&gt;&lt;BR /&gt;I have tried a simplified code like the one below here.&lt;BR /&gt;The error is exactly the same.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;The solution is probably something very simple...but i can't see what&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;// Experimental function for addPar updates
void BACDownload::TestParameterUpdates(API_LibPart&amp;amp; libPart)
{
	// Get the library part
	GSErrCode err = ACAPI_LibPart_Get(&amp;amp;libPart);
	if (err == NoError)
	{
		if (libPart.location != NULL)
		{
			delete libPart.location;
			libPart.location = NULL;
		}
	}

	// Define a parameter section
	API_LibPartSection section;
	BNZeroMemory(&amp;amp;section, sizeof(API_LibPartSection));
	section.sectType = API_SectParamDef;

	// Get parameter section
	GSHandle sectionHdl = NULL;
	err = ACAPI_LibPart_GetSection(libPart.index, &amp;amp;section, &amp;amp;sectionHdl, NULL);
	if (err) return;

	// Get current parameters
	double a, b;
	Int32 addParNum, i;
	API_AddParType** addPars;
	err = ACAPI_LibPart_GetParams(libPart.index, &amp;amp;a, &amp;amp;b, &amp;amp;addParNum, &amp;amp;addPars);
	if (err) return;
	
	// ..
	// Do nothing with the parameters
	// ..

	// Build a section handle with all parameters
	GSHandle Sect2DDrawHdl = NULL;
	err = ACAPI_LibPart_GetSect_ParamDef(&amp;amp;libPart, addPars, &amp;amp;a, &amp;amp;b, Sect2DDrawHdl, &amp;amp;sectionHdl);

	// Update our section
	err = ACAPI_LibPart_UpdateSection(libPart.index, &amp;amp;section, sectionHdl, NULL);
	// NOTE : Here above i get and error : APIERR_BADPARS :	-2130313112 : The passed parameters are inconsistent.

	BMKillHandle(&amp;amp;sectionHdl);
	ACAPI_DisposeAddParHdl(&amp;amp;addPars);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Oct 2021 06:13:34 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/ACAPI-LibPart-UpdateSection-error/m-p/308159#M1764</guid>
      <dc:creator>gehairing</dc:creator>
      <dc:date>2021-10-04T06:13:34Z</dc:date>
    </item>
  </channel>
</rss>

