Handling Warning Pop Up while using Edit.Family() method

I am not 100% familiar with what your code is doing above, but it seems it tries to handle all popups. This can become problematic as you could suppress an unknown warning that does something you want to handle in a different way. Below is how I handle popups. It allows you to simulate a person clicking on a particular button suppressing the warning in a pre-determined manner.

I use this in pyRevit but it should work all the same. You will want to make one change. I am printing the name of the box or a failed attempt. Since Dynamo does not use prints you will want to append these to a list and put them in "OUT = ".

The “print(“Dialog Box ID: {}”.format(boxId))” line will give you the name of the current popup. You will then need to add it to the appropriate list to be handled in a way that works for you. The archi-lab line (provided in the code will guide you through built in Revit buttons and the link to Microsoft will guide you to the IDs of standard buttons such as “ok”. These are the “args.OverrideResult(ID of button you want to press)”

def dialog_event_handler_function(sender, args):
		try:
			boxId = args.DialogId
			button1 = [List of all Dialogs you want to press the first botton]
			button2 = [List of all Dialogs you want to press the second botton]
			okButton = [List of all Dialogs you want to press ok]

			if boxId in button2:					 
				# https://archi-lab.net/dismissing-revit-pop-ups-the-easy-and-not-so-easy-ways/
				args.OverrideResult(1002)
			elif boxId in okButton:
				# search for IDOK https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-messagebox
				args.OverrideResult(1)
			elif boxId in button1:
				args.OverrideResult(1001)
			else:
				print("Dialog Box ID: {}".format(boxId))
		except Exception as e:
			print("Dialog Event Handle Filed: {}".format(traceback.format_exc()))
# add the above definition to the watch list
uiapp.DialogBoxShowing += EventHandler[DialogBoxShowingEventArgs](dialog_event_handler_function)

exicute your code here that generates the popup

# unsubscribe from the watcher. This will release the resources being used. 
# If you do not unsubscribe it will indefinitely be looking for popups. 
uiapp.DialogBoxShowing -= EventHandler[DialogBoxShowingEventArgs](dialog_event_handler_function)

Let us know if you have any questions,
Steven

1 Like