BIM Coordinator Program (INT) April 22, 2024

Find the next step in your career as a Graphisoft Certified BIM Coordinator!

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

How to unregister CatchNewElement observers?

Hi all,

 

Did anyone of you have success with unregistering a CatchNewElement observer?
I passed a `nullptr` for the handlerProc as described in the documentation.
Unfortunately the observer doesn't seem to unregister and my Add-On is still notified by new elements.
I've tried for all elemTypes (nullptr) and for specific ones.


Context
I try to keep the Debug versions of my Add-Ons so that they are not persistently loaded.
Then I can recompile them without going into the Add-On manager or restarting Archicad.
But of course it's necessary to check behaviors of used observers.
For that it's convenient to be able to turn them off again and the Add-On is automatically unloaded.

 

Best,
Bernd

Bernd Schwarzenbacher - Archicad Add-On Developer - Get Add-Ons & Archicad Tips on my Website: Archi-XT.com
8 REPLIES 8
ReignBough
Enthusiast

Did you also put the element type you want to stop catching new element event?

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

Yes I've also tried it with specifying the element type.

Bernd Schwarzenbacher - Archicad Add-On Developer - Get Add-Ons & Archicad Tips on my Website: Archi-XT.com
Akos Somorjai
Graphisoft
Graphisoft

Hi Bernd,

 

Have you tried to add: ACAPI_Element_InstallElementObserver (nullptr); as well?

 

Best, Akos

Hi Akos,

 

Thanks for the idea! I finally got around to trying it. Unfortunately that didn't help either. Still the same behavior,
I think I've already tried that before and this time I also tried several different orders and combinations of unregistering the observer with

  • ACAPI_Notify_CatchNewElements (nullptr, nullptr)
  • ACAPI_Notify_CatchNewElements (&tbItem, nullptr)
  • ACAPI_Notify_InstallElementObserver (nullptr)

and the equivalent ACAPI_Element_.... functions for AC27.

 

Is there a specific order of operations that you were thinking about?

 

Best,

Bernd

Bernd Schwarzenbacher - Archicad Add-On Developer - Get Add-Ons & Archicad Tips on my Website: Archi-XT.com
Akos Somorjai
Graphisoft
Graphisoft

Hi Bernd,

 

Have you also attached an observer? (AC27: `ACAPI_Element_AttachObserver()`)

There is an `ACAPI_Element_DetachObserver()` which may help.

 

The order I would call these:

CatchNewElements (&tbItem, ElementEventHandlerProc)

InstallElementObserver (ElementEventHandlerProc)

AttachObserver

...

DetachObserver

InstallElementObserver (nullptr)

CatchNewElements (&tbItem, nullptr)

 

Best, Akos

 

Hi Akos,

 

Thanks for the further input! It took me a while to give it another try.


So now I've tried it exactly as suggested by you, but it doesn't work unfortunately. As soon as I add the outermost CatchNewElements pair (register and unregister), the Add-On's FreeData function isn't called anymore. So to me it really seems, that unregistering of CatchNewElements doesn't signal Archicad that the Add-On can be fully unloaded.

 

Best,

Bernd

Bernd Schwarzenbacher - Archicad Add-On Developer - Get Add-Ons & Archicad Tips on my Website: Archi-XT.com
Joel Buehler
Enthusiast

maybe a stupid suggestion but have you iterated trugh all elements with the ACAPI_Element_DetachObserver(guidOfElementLoL) call bevore calling:

 

err = ACAPI_Element_CatchNewElement(nullptr, nullptr);
err = ACAPI_Element_InstallElementObserver(nullptr);

 

my observer works just fine with attach and detach. but i didt try to unload the plugin since mine is allways loaded. 

Hi Joel,

Not a stupid question at all! And thanks for chiming in with your experience 🙂

 

Yes I did try with detaching the observers of all elements first. Doesn't change anything and also it's the same behavior when working in an empty file.

Which makes kind of sense, since the new element observer is not attached to single elements anyway (although it might be the same function as the normal element observer).

Bernd Schwarzenbacher - Archicad Add-On Developer - Get Add-Ons & Archicad Tips on my Website: Archi-XT.com
Learn and get certified!

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!