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

Hi there,
I am trying to get the document from the families in my project to gather all their parameters in a list.

For this I am using FilteredElementColelctor(doc).OfClass(Family).ToElements() and then for each item say fam in the collector i do doc.EditFamily(fam)

This works but some of my families raise a pop up Warning window.

It’s a very very similar issue to this one : Re: How to dismiss popups when going into “EditFamily” from a project. - Autodesk Community - Revit Products

Which let to this Building Coder Wrapup Post

and based on this post I tryed to mix everything, namely wrapping up the transaction embedded in EditFamily() Method so I can use the swallower.

However I tweak the code, I can’t make it work. Here is what I have :

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

class Swallower(IFailuresProcessor):
	def PreprocessFailures(self, a):
		failures = a.GetFailureMessages()
		for  f in failures:
		    severity = a.GetSeverity()
		    if severity == FailureSeverity.Warning :
		      a.DeleteWarning(f)
		    else:
		      a.ResolveFailure(f)
		      return FailureProcessingResult.ProceedWithCommit	
		return FailureProcessingResult.Continue

log=[]

TransactionManager.Instance.ForceCloseTransaction()

for famili in UnwrapElement(IN[0]) :
    if famili.IsEditable :
        #log.append(1)
        with Transaction(doc.EditFamily(famili),"Open fam") as t :
            #log.append(2)
            t.Start()
            #log.append(3)
            failureOptions = t.GetFailureHandlingOptions()
            #log.append(4)
            failureOptions.SetFailuresPreprocessor(Swallower())
            t.SetFailureHandlingOptions(failureOptions)
            t.Commit()

OUT = log

Hopefully someone can guide me to solve this popup box handling !

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