Event handler problem postable command

Hello guys,
I’m struggling with event handler in dynamo. I want to supress TaskDialog from postable command.
Could you help me with this?

import clr
import System
from System import EventHandler
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import RevitCommandId
import Autodesk
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI.Events import DialogBoxShowingEventArgs
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication

def confirm(sender, eventArgs):
	return eventArgs.OverrideResult(TaskDialogResult.Ok)
	
bool = IN[0] 

if bool ==  True:

	CmndID = RevitCommandId.LookupCommandId('ID_PURGE_UNUSED')
	#cmdMonitor = RevitCommandEndedMonitor(uiapp)
	dialogEventHandler = EventHandler[DialogBoxShowingEventArgs](confirm)
	uiapp.DialogBoxShowing += dialogEventHandler
	uiapp.PostCommand(CmndID)
	RevitCommandId.LookupPostableCommandId
	uiapp.DialogBoxShowing -= dialogEventHandler
	
	error = 'Success'
else:
	error = 'Set IN[0] to true'

#Assign your output to the OUT variable
OUT = error

@Tomasz_Puchala did you ever figure this out?

Hi,

There are a few packages which use a Purge node, Orchid & Genius Loci, perhaps also have a look here?

Cheers,

Mark