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

How to get active view in ArchiCAD API?

Tran Thanh Lo
Booster

hi guys,

Do you know how to get active view?

(I think I need to use API_NavigatorItem, But I couldn't do it)

If you know, please help me

Thank you very much

5 REPLIES 5

Hi,

 

There's no function to get the active view directly as far as I know.

But you can workaround this with using with a View Notification Handler.

 

You have to register the notification handler in the Initialize function:

 

ACAPI_Notify_CatchViewEvent (APINotifyView_Opened, API_MyViewMap, ViewNoticationHandlerProc);

 

This has to be done separately for every API_NavigatorMapID you need. So you'll have to use a bit of trial and error to figure out which ones you'll need.

And the handler would look something like this:

static GSErrCode __ACENV_CALL ViewNoticationHandlerProc (const API_NotifyViewEventType* viewEvent)
{
	switch (viewEvent->notifID) {
	case APINotifyView_Opened: {
		// Do something here with `viewEvent->itemGuid`
		break;
	}
	default: break;
	}

	return NoError;
}

 

Also the Add-On needs to be registered as a preloaded Add-On. So return API_Addon_Preload in CheckEnvironment.

 

Hope that helps!

Bernd

Hi @BerndSchwarzenbacher ,

I followed your tutorials, but it still doesn't work? Can you check and tell me where I'm wrong

This is my code:

 

 

API_AddonType __ACENV_CALL 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;
}



static GSErrCode __ACENV_CALL ViewNoticationHandlerProc(const API_NotifyViewEventType* viewEvent)
{

switch (viewEvent->notifID) {
case APINotifyView_Opened: {

// Do something here with `viewEvent->itemGuid`
WriteReport_Alert("View");
break;
}
default: break;
}

return NoError;
}


GSErrCode __ACENV_CALL Initialize(void)
{
GSErrCode err = ACAPI_Install_MenuHandler(ID_MENU_STRINGS, MenuCommandHandler);

API_NavigatorMapID mapId = API_MyViewMap;

ACAPI_Notify_CatchViewEvent(APINotifyView_Opened, mapId, ViewNoticationHandlerProc);

if (err != NoError)
DBPrintf("3D_Test:: Initialize () ACAPI_Install_MenuHandler failed\n");


return err;
} // Initialize

 

received_3152864891523556.png

 

Hi @BerndSchwarzenbacher , Can you help me?

I'm quite busy right now, but tomorrow I'll have more time to take a closer look.

Please specify what exactly is not working.
What did you try to do in the program and what did you expect to happen?

From a quick look at the code it seems OK. Maybe try different NavigatorMapIDs like API_ProjectMap, API_UndefinedMap, API_PublicViewMap.

I did a few quick tests by opening different view maps in Archicad and checking which map ID is used in the triggered view notification.
Here's the mapping of Archicad Navigator Map -> API_NavigatorMapIDs when listening to APINotifyView_Opened:

  • Project Map (Stories, Elevations, Schedules, ...) -> API_ProjectMap
  • API_PublicViewMap
  • Layout Book & Publisher Sets -> API_UndefinedMap

Couldn't find anything that triggered the API_MyViewMap. I'm sure I used it before for something, but can't remember now.

 

Hope that helps,
Bernd