We value your input! Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey
2023-06-16 04:13 PM
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
2023-07-26 05:45 AM - edited 2023-07-26 05:46 AM
Did you also put the element type you want to stop catching new element event?
2023-08-03 02:44 PM
Yes I've also tried it with specifying the element type.
2023-10-19 08:57 AM
Hi Bernd,
Have you tried to add: ACAPI_Element_InstallElementObserver (nullptr); as well?
Best, Akos
2023-10-25 10:23 PM
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
and the equivalent ACAPI_Element_.... functions for AC27.
Is there a specific order of operations that you were thinking about?
Best,
Bernd
2023-11-08 01:42 AM
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
2024-02-09 07:59 AM - edited 2024-02-09 08:00 AM
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
2024-02-26 10:41 AM
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.
2024-02-27 09:19 AM
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).