cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 
Archicad C++ API
About Archicad add-on development using the C++ API.
SOLVED!

why NotificationHandler of ACAPI_ProjectOperation_CatchProjectEvent get zero body?

sxs
Booster

  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.

11 REPLIES 11

To supplement the explanation to the readers, I am currently using ACAPI_Notification_CatchViewEvent(APINotifyView_Opened, API_PublicViewMap, ViewNotificationHandlerProc) Replaced ACAPI_ProjectOperation_CatchProjectEvent(APINotify_AllInputFinished, NotificationHandler),
The timing of the ViewNotificationHandlerProc trigger is later, which is more in line with my needs.

Solution
	//
	{
		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);
	}

 

sxs_0-1748509658786.png

 

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!