Failure Handling Options Help (Warning Suppression)

I’m trying to suppress the errors that arise when you automatically publish coordinates, via transaction failure handling options.

Python Script...
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# Import RevitAPI
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
# Import ToProtoType, ToRevitType geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)

# Import DSCore nodes in Dynamo
clr.AddReference('DSCoreNodes')
import DSCore
from DSCore import *

# Import python library
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
import os
import shutil
import math
# Import math library
from math import *

#Import Data and Time
from datetime import datetime
now = datetime.now()

#Import System Library
import System
from System.Collections.Generic import *
from System.IO import Directory, Path

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

#Preparing input from dynamo to revit
rvtLinkInstances = UnwrapElement(IN[0])
result = []
#Do some action in a Transaction

projSite = None
projLocName = None

ProLoc = UnwrapElement(IN[1])
orgin = XYZ(0, 0, 0)
projPos = ProLoc.get_ProjectPosition(orgin)
projLocName = ProLoc.Name
projPosEW = projPos.EastWest
projPosNS = projPos.NorthSouth
projPosEl = projPos.Elevation
projPosAngle = projPos.Angle
projSite = ProLoc.GetSiteLocation()
projSiteLat = projSite.Latitude
projSiteLong = projSite.Longitude
projSiteTimeZ = projSite.TimeZone

trigger = True
#TransactionManager.Instance.EnsureInTransaction(doc)
for rvtLinkInstance in rvtLinkInstances:
	linkdoc = rvtLinkInstance.GetLinkDocument()
	linkdocpath = linkdoc.PathName
	message = "Project Location of specific name already exist"
	message3 = "Project Location of specific name already exist"
	rvtlinktype = doc.GetElement(rvtLinkInstance.GetTypeId())
	TransactionManager.Instance.ForceCloseTransaction()
	rvtlinktype.Unload(None)	
	newdoc = app.OpenDocumentFile(linkdocpath)
	currentLinkLocation = newdoc.ActiveProjectLocation
	Linklocations = newdoc.ProjectLocations
	for Linklocation in Linklocations:
		if Linklocation.Name == projLocName:
			trigger = False
			break
		else: continue
	if trigger:
		t = Transaction(newdoc, "Create Project Location")
		t.Start()
		try: 
			newloc = currentLinkLocation.Duplicate(projLocName)
			newloc.set_ProjectPosition(orgin,projPos)
			newlocsite = newloc.GetSiteLocation()
			newlocsite.Latitude = projSiteLat
			newlocsite.Longitude = projSiteLong
			newlocsite.TimeZone = projSiteTimeZ
			#newloc = ProjectLocation.Create(newdoc, projSite.Id, projLocName)
			message = "Project Location successfully duplicated/created"
			t.Commit()
		except Exception as e: 
			message = "Could not create project location due to: " + str(e)
			t.RollBack() 
	newdoc.Close()
	rvtlinktype.Reload() 
	result.append(message)
	
#Publish newloc 

for rvtLinkInstance in rvtLinkInstances:
	linkdoc = rvtLinkInstance.GetLinkDocument()
	message2 = "Project Location already Published"
	TransactionManager.Instance.ForceCloseTransaction()
	Linklocations = linkdoc.ProjectLocations
	for Linklocation in Linklocations:
		if Linklocation.Name == projLocName:
			t = Transaction(doc, "Publish Project Location")
			fho = FailureHandlingOptions.SetDelayedMiniWarnings(True)
			t.SetFailureHandlingOptions(fho)
			t.Start()
			try: 
				doc.PublishCoordinates(LinkElementId(rvtLinkInstance.Id,Linklocation.Id))
				message2 = "Project Location successfully published"
				t.Commit()
			except Exception as e: 
				message2 = "Could not publish project location due to: " + str(e)
				t.RollBack() 
		else: continue	
	result.append(message2)

#TransactionManager.Instance.TransactionTaskDone()
#Final output
debug = False
#debug = True#Comment to turn off
if debug:
	OUT=['orgin: ', orgin, 'projPos: ' , projPos, 'projLocName: ', projLocName, 'projPosEW: ', projPosEW, 'projPosNS: ', projPosNS, 'projPosEl: ', projPosEl, 'projPosAngle: ', projPosAngle,'projSite: ', projSite, 'projSiteLat: ' , projSiteLat, 'projSiteLong: ' , projSiteLong, 'projSiteTimeZ: ', projSiteTimeZ, 'result: ', result]

else:
	OUT = result


My issue is that I have no idea what the second argument for this method is, it isn’t listed on the SetDelayedMiniWarnings Method site.

Am I creating my FailureHandlingOptions object wrong? I am kinda confused on how this one works because there isn’t a constructor and I don’t know where to pull and existing one from.

Is there another way to automatically close this error dialog box?

Ok in retrospect that should have been pretty obvious,


However, even though I may have my failure handling working correctly my warning dialog box still shows :confused:

Modal Handling On

Modal Handling Off

Delayed Mini Warnings On

My best guess is that this dialog box is not controlled by failure handling because it is a warning, does anyone know how to suppress these?

I am still not sure how event handlers work in IronPython but this post may help you.

1 Like

This stuff is a little out of my league. I think I have found what is needed, however I have no idea how to execute it.

I believe that I need to create an event handler with my desired event (message box) arguments.


In the arguments, I would assign to override the result to IDOK or 1.

I tried to just assign the arguments earlier without an event handler, like this:

MessageBoxShowingEventArgs.OverrideResult(1)

However I was given the error that I was only providing 1 of the 2 arguments required and I am assuming that the second argument is referring to the message box object. Bringing me to the DialogBoxShowing event.

Are there any examples of these UIAppplication Event handlers in python?

EDIT: I think I found one: https://www.revitapidocs.com/code/#Python_RegisterEventHandler-py

You can look into using that, but I think it might not actually work, for reasons outlined here. The example you’ve linked to looks like it’s meant to be run using PyRevit, but I don’t really have enough knowledge myself to say whether it will or won’t work.

Yeah I’m not really having much luck.

Is there really no common way to suppress these message dialog boxes in dynamo?

This is now a year-old topic but for the interested readers, this post has a sample code to tackle the issue of handling failures (with Warning level severity) in transactions:
Failure Handling With Dynamo-Python

1 Like