<?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: Replacing one BIM Object with Another Object in the Archicad Project. in Archicad C++ API</title>
    <link>https://community.graphisoft.com/t5/Archicad-C-API/Replacing-one-BIM-Object-with-Another-Object-in-the-Archicad/m-p/653848#M10175</link>
    <description>&lt;P&gt;Hi, When you'd change an object, the index(libInd) only seems not enough. I think you need to set the mask ACAPI_ELEMENT_MASK_SET() as first, and pass the new object memo like:&lt;BR /&gt;ACAPI_Element_Change (&amp;amp;element, &amp;amp;mask, &amp;amp;memo, APIMemoMask_AddPars, true);&lt;BR /&gt;Please check the API Examples, you can find similar code which is using the command above.&lt;BR /&gt;HTH.&lt;/P&gt;</description>
    <pubDate>Tue, 04 Mar 2025 03:12:26 GMT</pubDate>
    <dc:creator>Hiromichi Shinkawa</dc:creator>
    <dc:date>2025-03-04T03:12:26Z</dc:date>
    <item>
      <title>Replacing one BIM Object with Another Object in the Archicad Project.</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Replacing-one-BIM-Object-with-Another-Object-in-the-Archicad/m-p/653562#M10169</link>
      <description>&lt;P&gt;Hi there! I'm trying to replace one BIM Object (which is already available in the Embedded Library) with another BIM Object using the code below. I'm finding the Lib_Part indices of both objects and setting the libInd of the old object to the new object's libInd (element.object.libInd = replacementLibPart.index;).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm facing&amp;nbsp;&lt;SPAN&gt;APIERR_REFUSEDCMD error or&amp;nbsp;APIERR_BADPARS error, when the code reaches&amp;nbsp;ACAPI_Element_Change(). No Matter what I try, I'm unable to fix this. Can you please help me fix this?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Please let me know if my approach has any issues.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks in Advance!.&lt;/SPAN&gt;&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;// Function to find an object by name
API_LibPart FindLibPartByName(const char* partName) {
	API_LibPart libPart;
	BNZeroMemory(&amp;amp;libPart, sizeof(API_LibPart));

	GSErrCode err;
	Int32 numLibParts;
	ACAPI_LibraryPart_GetNum(&amp;amp;numLibParts);

	for (Int32 i = 1; i &amp;lt;= numLibParts; i++) {
		BNZeroMemory(&amp;amp;libPart, sizeof(API_LibPart));
		libPart.index = i;

		err = ACAPI_LibraryPart_Get(&amp;amp;libPart);
		char	docuname[256];
		GS::UniString docName = GS::UniString(libPart.docu_UName);
		const char* cString = docName.ToCStr().Get();

		if (err == NoError &amp;amp;&amp;amp; strcmp(cString, partName) == 0) {
			return libPart;
		}
	}

	libPart.index = 0; // Return invalid index if not found
	return libPart;
}

// Function to replace all instances of an old object with a new one
GSErrCode BrowserPalette::ReplaceBIMObjects(const char* oldObjectName, const char* newObjectName) {

	// Get current object's library part
	API_LibPart oldLibPart;
	BNZeroMemory(&amp;amp;oldLibPart, sizeof(API_LibPart));

	//Adding oldobjectname's libpart
	oldLibPart = FindLibPartByName(oldObjectName);
	GS::UniString OldLibpartName(oldLibPart.docu_UName);

	API_LibPart replacementLibPart;
	BNZeroMemory(&amp;amp;replacementLibPart, sizeof(API_LibPart));

	replacementLibPart = FindLibPartByName(newObjectName);
	GS::UniString newLibpartName(replacementLibPart.docu_UName);

	if (ACAPI_LibPart_Get(&amp;amp;oldLibPart) == NoError) {

		ACAPI_WriteReport("Found Object: %s", true, OldLibpartName);

		if (ACAPI_LibPart_Get(&amp;amp;replacementLibPart) == NoError) {

			ACAPI_WriteReport("Replacing %s with %s", true, OldLibpartName.ToCStr().Get(), newLibpartName.ToCStr().Get());

			// Update the object's library part reference
			GS::Array&amp;lt;API_Guid&amp;gt; objectList;
			ACAPI_Element_GetElemList(API_ObjectID, &amp;amp;objectList);

			for (const auto&amp;amp; objGuid : objectList) {
				API_Element element;
				BNZeroMemory(&amp;amp;element, sizeof(API_Element));
				element.header.guid = objGuid;

				if (ACAPI_Element_Get(&amp;amp;element) == NoError) {

					if (element.object.libInd == oldLibPart.index) {
						//ACAPI_WriteReport("Found Element: %s", true, element.object.libInd);

						element.object.libInd = replacementLibPart.index; // Replace with new object index

						GSErrCode err = ACAPI_CallUndoableCommand("Change Object",
							[&amp;amp;]() -&amp;gt; GSErrCode {
							return ACAPI_Element_Change(&amp;amp;element, nullptr, nullptr, 0, false);
						});
						
						//GSErrCode err = ACAPI_Element_Change(&amp;amp;element, nullptr, nullptr, 0, true);

						if (err != NoError) {
								ACAPI_WriteReport("Error updating object: %d", true, err);
						}

					}
				}
			}

		}
		else {
			ACAPI_WriteReport("Replacement object %s not found in Embedded Library.", true, newLibpartName.ToCStr().Get());
		}
	}

	return NoError;
	}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2025 09:54:53 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Replacing-one-BIM-Object-with-Another-Object-in-the-Archicad/m-p/653562#M10169</guid>
      <dc:creator>KirthikaSrinivasan-L</dc:creator>
      <dc:date>2025-02-28T09:54:53Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing one BIM Object with Another Object in the Archicad Project.</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Replacing-one-BIM-Object-with-Another-Object-in-the-Archicad/m-p/653848#M10175</link>
      <description>&lt;P&gt;Hi, When you'd change an object, the index(libInd) only seems not enough. I think you need to set the mask ACAPI_ELEMENT_MASK_SET() as first, and pass the new object memo like:&lt;BR /&gt;ACAPI_Element_Change (&amp;amp;element, &amp;amp;mask, &amp;amp;memo, APIMemoMask_AddPars, true);&lt;BR /&gt;Please check the API Examples, you can find similar code which is using the command above.&lt;BR /&gt;HTH.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Mar 2025 03:12:26 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Replacing-one-BIM-Object-with-Another-Object-in-the-Archicad/m-p/653848#M10175</guid>
      <dc:creator>Hiromichi Shinkawa</dc:creator>
      <dc:date>2025-03-04T03:12:26Z</dc:date>
    </item>
  </channel>
</rss>

