2025-05-22 10:56 AM
Hi, everyone:
first, this is part of my code:
static GSErrCode NotificationHandler(API_NotifyEventID notifID, Int32 param)
{
char msgStr[256];
switch (notifID) {
case APINotify_New: CHCopyC("APINotify_New", msgStr); break;
case APINotify_NewAndReset: CHCopyC("APINotify_NewAndReset", msgStr); break;
case APINotify_Open: CHCopyC("APINotify_Open", msgStr); break;
case APINotify_PreSave: CHCopyC("APINotify_PreSave", msgStr); break;
case APINotify_Save: CHCopyC("APINotify_Save", msgStr); break;
case APINotify_Close: CHCopyC("APINotify_Close", msgStr); break;
case APINotify_Quit: CHCopyC("APINotify_Quit", msgStr); break;
case APINotify_SendChanges: CHCopyC("APINotify_SendChanges", msgStr); break;
case APINotify_ReceiveChanges: CHCopyC("APINotify_ReceiveChanges", msgStr); break;
case APINotify_ChangeProjectDB: CHCopyC("APINotify_ChangeProjectDB", msgStr); break;
case APINotify_ChangeWindow: CHCopyC("APINotify_ChangeWindow", msgStr); break;
case APINotify_ChangeFloor: CHCopyC("APINotify_ChangeFloor", msgStr); break;
case APINotify_ChangeLibrary: CHCopyC("APINotify_ChangeLibrary", msgStr); break;
case APINotify_AllInputFinished: CHCopyC("APINotify_AllInputFinished", msgStr); break;
}
//
void* origSight;
auto err = ACAPI_Sight_SelectSight(nullptr, &origSight);
if (err != NoError) {
//ErrorBeep("Cannot switch to the 3D sight", err);
ACAPI_WriteReport("Cannot switch to the 3D sight", true);
return err;
}
//
{
Int32 nbody;
err = ACAPI_ModelAccess_GetNum (API_BodyID, &nbody);// nbody is zero, but there are many elements
}
ACAPI_WriteReport(msgStr, true);
return NoError;
} // NotificationHandler
API_AddonType CheckEnvironment (API_EnvirParams* envir)
{
RSGetIndString (&envir->addOnInfo.name, ID_ADDON_INFO, 1, ACAPI_GetOwnResModule ());
RSGetIndString (&envir->addOnInfo.description, ID_ADDON_INFO, 2, ACAPI_GetOwnResModule ());
return APIAddon_Preload;// this is important
} // CheckEnvironment
GSErrCode Initialize (void)
{
auto err = ACAPI_ProjectOperation_CatchProjectEvent(APINotify_AllInputFinished, NotificationHandler);
return NoError;
} // Initialize
my goal is to get geometry of all elements in NotificationHandler,but it does not works, the count of Body i get is zero.
so, what's wrong with the code.
Solved! Go to Solution.
2025-05-28 01:49 PM
Try bringing the 3D window to the front (see my separate reply on a different thread) and then use ACAPI_View_Rebuild. I think you may need to pass a true value in the doRebuildAndRegenerate parameter.
2025-05-29 11:07 AM
//
{
API_WindowInfo windowInfo;
API_DatabaseInfo origDB, planDB;
API_Element element;
GS::Array<API_Guid> elemList;
GSErrCode err;
BNZeroMemory(&planDB, sizeof(API_DatabaseInfo));
planDB.typeID = APIWind_3DModelID;
//ACAPI_Database(APIDb_GetCurrentDatabaseID, &origDB, nullptr);
ACAPI_Database_ChangeCurrentDatabase(&planDB);
//
BNZeroMemory(&windowInfo, sizeof(API_WindowInfo));
windowInfo.typeID = APIWind_3DModelID;
windowInfo.databaseUnId = planDB.databaseUnId;
err = ACAPI_Window_ChangeWindow(&windowInfo);
}
//
if (err == NoError)
{
bool is_rebuild = true;
ACAPI_View_Rebuild(&is_rebuild);
}
//
{
{
void* origSight;
GSErrCode err;
err = ACAPI_Sight_SelectSight(nullptr, &origSight);
}
//
Int32 nbody;
auto err = ACAPI_ModelAccess_GetNum(API_BodyID, &nbody);
WriteReport_Alert("body num %d", nbody);
}
2025-05-22 03:30 PM
The function ACAPI_ModelAccess_GetNum will count the number of bodies in the 3D view - is anything displayed in the 3D view when you call it? Also, have you checked if an error code is returned from the function?
As an aside, I wouldn't use this function every time a project notification is emitted - otherwise this will be called repeatedly for no purpose. Also don't forget to call ACAPI_Sight_SelectSight afterward to switch back to the original view when you've collected the data.
2025-05-23 04:22 AM
Hi,
1,This is the 3d model:
I don't know if I called it at the wrong time, but I can get wall by this code:
GS::Array<API_Guid> wallList;
ACAPI_Element_GetElemList(API_WallID, &wallList);
2,I have confirmed that it returned NoError.
2025-05-23 12:22 PM
@sxs wrote:
I don't know if I called it at the wrong time, but I can get wall by this code:
GS::Array<API_Guid> wallList; ACAPI_Element_GetElemList(API_WallID, &wallList);
2,I have confirmed that it returned NoError.
I need to know a bit more about you are planning to develop to answer the question properly. Do you want 3D geometry (bodies, faces, vertices etc) or information about the construction elements in the project? I'm asking because the 2 commands you mentioned (ACAPI_ModelAccess_GetNum and ACAPI_Element_GetElemList) extract data from two different sources:
2025-05-23 12:31 PM
Thank you, I understand now。
I want 3D geometry (bodies, faces, vertices etc), so What api is suitable for me?
2025-05-23 12:39 PM
How to get 3D geometry (bodies, faces, vertices etc) in NotificationHandler of project notification?
Maybe you would recommend ACAPI_Sight_SelectSight, but I've tried it and it didn't work。
2025-05-23 01:54 PM - edited 2025-05-23 10:56 PM
@sxs wrote:
How to get 3D geometry (bodies, faces, vertices etc) in NotificationHandler of project notification?
Maybe you would recommend ACAPI_Sight_SelectSight, but I've tried it and it didn't work。
it would help to understand what you want to do. I suspect that using project event notifications (open, save, close etc) are probably not what you want, but I can't definitely say without knowing why you want the 3D geometry. If a user has just opened a project (for example) the model will always be empty because it hasn't been viewed yet. Archicad doesn't automatically do this because building 3D geometry can be very processor-intensive and it's wasted until the user has actually asked to see something specific in 3D.
If you want to export the 3D geometry in a different format (for example) then there are APIs for plugging directly into Archicad's 'Save As…' functionality. If you explain what you would like to do, I could point in the best direction for accomplishing it.
2025-05-26 03:34 AM
“If you want to export the 3D geometry in a different format (for example)”, it is my goal, but I want to do this without any user operation like clicking menu button, I want to create an automic plugin to export the 3D geometry in a different format. The automation plugin means that once Archicad completes opening the model file, the plugin will run directly without any user intervention like clicking menu button.
2025-05-28 01:49 PM
Try bringing the 3D window to the front (see my separate reply on a different thread) and then use ACAPI_View_Rebuild. I think you may need to pass a true value in the doRebuildAndRegenerate parameter.
2025-05-29 08:49 AM
Okay, thank you. I'll give it a try