Subscribe to event

How to check whether the code is subscribe to some solidworks event?

For example, I want to know the addon was subscribed to event DPartDocEvents_NewSelectionNotifyEventHandler, if not - then subscribe if yes - continue the program.

SolidworksApi macros
Answers 2
AT
AT 2013-12-19 Best Answer

Do you want to check that you have already subscribed to avoid multiple handling of the same event? If so I would simply suggest to unsubscribe of the event before subscribing:

… -= DPartDocEvents_NewSelectionNotifyEventHandler (…)

… += DPartDocEvents_NewSelectionNotifyEventHandler (…)

If the event is not subscribed it will just skip this otherwise will unsubscribe and subscribe again so you can be sure that it is always only one handler.

SF
SF 2013-12-19

Sorry, I put the topic at the beginning of incorrect event.

I am processing OnBufferSwap ()

In connection with this question: would not it be too resource-intensive, unsubscribe and subscribe to the event? Because OnBufferSwap happen very often.