Archicad 29 C++ API
Loading...
Searching...
No Matches
API_HotlinkCacheGenerator Class Referenceabstract

Base class for generating the updated content of a hotlink cache. More...

#include <APIdefs_Database.h>

Public Member Functions

virtual GSErrCode GenerateCacheContentForHotlinkNode (const API_Guid &hotlinkNodeGuid)=0
 A callback function to generate the cache content for hotlink nodes.
 

Detailed Description

Base class for generating the updated content of a hotlink cache.

Remarks
When a hotlink node is created by the add-on, the content of the hotlink cache must be generated also. In order to create the appropriate elements and attributes into the cache database, you need to pass an API_HotlinkCacheGenerator object to the ACAPI_Hotlink_UpdateHotlinkCache function. When the GenerateCacheContentForHotlinkNode method of the object is called back from the hotlink update function, the standard element and attribute creator functions (like ACAPI_Element_Create and ACAPI_Attribute_Create) are redirected to create elements and attributes into the hotlink cache database, rather than the project database.
If the GenerateCacheContentForHotlinkNode function return an error, the update process is canceled.
Example
class HotlinkCacheGenerator: public API_HotlinkCacheGenerator {
public:
virtual GSErrCode GenerateCacheContentForHotlinkNode (const API_Guid& hotlinkNodeGuid);
} hotlinkCacheGenerator;
GSErrCode HotlinkCacheGenerator::GenerateCacheContentForHotlinkNode (const API_Guid& hotlinkNodeGuid)
{
API_HotlinkNode hotlinkNode = {};
hotlinkNode.guid = hotlinkNodeGuid;
GSErrCode err = ACAPI_Hotlink_GetHotlinkNode (&hotlinkNode);
if (err == NoError && hotlinkNode.sourceLocation != nullptr) {
IO::File sourceFile (*hotlinkNode.sourceLocation);
err = sourceFile.GetStatus ();
if (err == NoError) {
// read the file, create elements and attributes into the cache database
}
}
if (hotlinkNode.sourceLocation != nullptr)
delete hotlinkNode.sourceLocation;
if (hotlinkNode.userData.data != nullptr)
BMKillPtr (&hotlinkNode.userData.data);
return err;
}
void UpdateHotlink ()
{
GS::HashSet<API_Guid> alreadyUpdatedNodes;
GS::Array<API_Guid> elemList;
for (GS::Array<API_Guid>::ConstIterator it = elemList.Enumerate (); it != nullptr; ++it) {
API_Element hotlinkElem;
BNZeroMemory (&hotlinkElem, sizeof (API_Element));
hotlinkElem.header.guid = *it;
if (ACAPI_Element_Get (&hotlinkElem) == NoError) {
if (!alreadyUpdatedNodes.Contains (hotlinkElem.hotlink.hotlinkNodeGuid)) {
ACAPI_Hotlink_UpdateHotlinkCache (&hotlinkElem.hotlink.hotlinkNodeGuid, &hotlinkCacheGenerator);
alreadyUpdatedNodes.Add (hotlinkElem.hotlink.hotlinkNodeGuid);
}
}
}
}

Member Function Documentation

◆ GenerateCacheContentForHotlinkNode()

virtual GSErrCode API_HotlinkCacheGenerator::GenerateCacheContentForHotlinkNode ( const API_Guid & hotlinkNodeGuid)
pure virtual

A callback function to generate the cache content for hotlink nodes.

Parameters
hotlinkNodeGuidGuid of the hotlink node.
Returns
Returns error code.