Archicad C++ API
About Archicad add-on development using the C++ API.

Delete Specific Hotlink Element (Not HotlinkNode)

kristkun
Participant

Hello,

I am trying to delete the Hotlink Element via API using ACAPI_Element_Delete with NoError(0) results but the Hotlink elements were not deleted in my project.

My end goal is to delete hotlink elements on specific floors. I don't want to delete all hotlink referenced to a single source/Hotlink Node.

I initially tried to use ACAPI_Element_Delete() to delete all hotlink elements based on their element guids. (err==0)

 

// Get all Hotlink elements
GS::Array<API_Guid> elemGuidList;
err = ACAPI_Element_GetElemList(API_HotlinkID, &elemGuidList);
if (err != NoError) return err;

// Delete all Hotlink elements
err = ACAPI_CallUndoableCommand("Element Test - Delete 2D HLM Element", [&]() -> GSErrCode {
				return ACAPI_Element_Delete(elemGuidList);
});
if (err != NoError) return err;

 

kristkun_0-1714846987012.png


But after i executed the process/code. the element still exist in my project

kristkun_1-1714847057034.png



I already tried using ACAPI_Hotlink_DeleteHotlinkNode() but again, this method will delete all elements that uses/referenced to that hotlink node(I dont need to delete all hotlink elements based on the hotlink node)

Any Idea how can i delete specific hotlink element Example there are 2 hotlink element in ground floor and first floor(story) using the same hotlink source, I only want to delete the hotlink in first floor(Story) [Which is possible using Archicad software/done manually]

1 REPLY 1
kristkun
Participant

[Update]
I realized that the hotlink module are somewhat group of elements that is why I tried getting the group elements and delete those elements.
However, It did work in one of my hotlink but not with my other hotlinks. Not sure why it was not returning any group elements(Empty GS::Array<API_Guid>) based on the hotlink group id when using ACAPI_Grouping_GetGroupedElems()
Still not sure what is the best approach to successfully delete a placed Hotlink.

Here is my current code:

 

// Get all hotlink elements
GS::Array<API_Guid> elemGuidList;
err = ACAPI_Element_GetElemList(API_HotlinkID, &elemGuidList);
DBPrintf("Number of found element type: %ld\n", elemGuidList.GetSize());
if (err != NoError) return err;

API_Element  element;
GSErrCode elemErr;
std::vector<API_Element> elemList;
for (GS::Array<API_Guid>::ConstIterator it = elemGuidList.Enumerate(); it != nullptr; ++it)
{
	BNZeroMemory(&element, sizeof(API_Element));
	element.header.guid = *it;
	elemErr = ACAPI_Element_Get(&element);
	if (elemErr == NoError)
	{
		elemList.push_back(element);

		DBPrintf("2D Hotlink Group Guid: %s\n", APIGuidToString(element.hotlink.hotlinkGroupGuid).ToCStr().Get());
		GS::Array<API_Guid> deleteGuids = {};
		err = ACAPI_Grouping_GetGroupedElems(element.hotlink.hotlinkGroupGuid, &deleteGuids);
		if (err != NoError) return err;
		err = ACAPI_CallUndoableCommand("Element Test - Delete 2D HLM Elements", [&]() -> GSErrCode {
			return ACAPI_Element_Delete(deleteGuids);
			});
		if (err != NoError) return err;

	}
}

 

 
Can be deleted: 2RF2-1.mod
Cannot be deleted: 3R-1.mod