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

ACAPI_Element_Get crashes

Anonymous
Not applicable
Hi,
I need to get rid of hotlinks created by my add-on, and I've found a nice example in the Element_Test code.
But for a mysterious reason, Archicad crashes when I call the ACAPI_Element_Get function...
Here's the code :

	//Function's error code
	GSErrCode err = NULL;
	//Containing the hotlink
	API_Element element;

	GS::Array<API_Guid> nodeRefList;
	if (ACAPI_Database (APIDb_GetHotlinkNodesID, NULL, &nodeRefList) == NoError) 
	{
		for (UIndex iNode = 0; iNode < nodeRefList.GetSize (); iNode++) 
		{
			BNZeroMemory (&element, sizeof (API_Element));
			element.header.typeID = API_HotlinkID;
			element.header.guid = nodeRefList[iNode];
			ACAPI_OpenUndoableSession("Effacer module");

         //Below is the crashing sentence
			err = ACAPI_Element_Get(&element);

			ACAPI_Database(APIDb_DeleteHotlinkNodeID, &nodeRefList[iNode], NULL);
			ACAPI_CloseUndoableSession();
		}
	}
My first thought was that this function needed to be into an undoable session, but I still have the same issue...
And I can't check the generated GSErrCode because Archicad crashes as soon as the function appear (no matter if the function is checked by "try...catch" method. Archicad just close everything and shows a nice BugReporter window...).
Does anyone have a clue ?

Thanks !
1 REPLY 1
ReignBough
Enthusiast
I've got the same problem. But I am using API_HotlinkNode instead of API_Element. Here is my code:

GS::Array<API_Guid> nodeRefList;
API_HotlinkTypeID type = APIHotlink_Module;
GSErrCode err = ACAPI_Database(APIDb_GetHotlinkNodesID, &type, &nodeRefList);
DBPrintf("node count: %d", nodeRefList.GetSize());
if (err==NoError)
{
  UInt32 len = nodeRefList.GetSize();
  for (UInt32 i=0; i<len; ++i)
  {
    API_HotlinkNode hotlinkNode;
    BNZeroMemory(&hotlinkNode, sizeof(API_HotlinkNode));
    hotlinkNode.guid = nodeRefList;
    hotlinkNode.type = type;
    err = ACAPI_Database(APIDb_GetHotlinkNodeID, &hotlinkNode, NULL);
    if (err==NoError)
    {
      //... do something ...//

      if (hotlinkNode.sourceLocation!=NULL)
        delete hotlinkNode.sourceLocation;
      if (hotlinkNode.userData.data!=NULL)
        BMKillPtr (&hotlinkNode.userData.data);
    }
    else
      return err;
  }
}
else
  return err;
I simply print the data (DBPrintf()) on a Debug Window (DebugView). The data was printed but still the function crashes on exit.

Help anyone?
~ReignBough~
ARCHICAD 26 INT (from AC18)
Windows 11 Pro, AMD Ryzen 7, 3.20GHz, 32.0GB RAM, 64-bit OS