Hi,
I’m making a simple model checker and looking for loadable families which return a warning or error when ‘edited’ (opened) from a project. I would like to return some information about the family to the user.
I therefore want to suppress every dialogue which might popup while ‘opening’ these families. I won’t be saving the families, so it doesn’t matter if elements are deleted, whatever is required.
I have been looking at this very interesting post:
Hello
here is an example with IFailuresPreprocessor, to be improved if necessary
[image]
import clr
import sys
import System
from System.Collections.Generic import List, IList, Dictionary
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
from Autodesk.Revit.UI.Events import ViewActivatedEventArgs, ViewActivatingEventArgs, DialogBoxShowingEventArgs
clr.AddReference('RevitServices')
import RevitServic…
Unfortunately, however, for me, it does not suppress the dialogue.
There is also this which appears to be working in the same way (post 20):
Any thoughts greatfully received.!
Mark
Supress Dialogue.rvt (456 KB)
Dialogue Suppress.dyn (10.0 KB)
hi @Mark.Ackerley
try this, I think it can be improved, (thanks @SeanP for the original C# code)
Note : you can remove the logger if you don’t use it
import clr
import sys
import System
from System.Collections.Generic import List, IList, Dictionary
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Events import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
from Autodesk.Revit.UI.Events import ViewActivatedEventArgs, ViewActivatingEventArgs, DialogBoxShowingEventArgs
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
projDoc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = DocumentManager.Instance.CurrentUIApplication.Application
my_path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments)
pf_path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFilesX86)
sys.path.append(pf_path + '\\IronPython 2.7\\Lib')
import logging
import traceback
## Start create logger Object ##
logger = logging.getLogger("DimissDialog")
# set to DEBUG
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s :: %(levelname)s :: %(funcName)s :: %(message)s')
# create handler
file_handler = logging.FileHandler(my_path + '\\' + projDoc.Title + 'DimissDialog.log', mode='w')
file_handler.setLevel(logging.DEBUG)
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
logger.disabled = False
def ControlledApplication_FailuresProcessing(sender, e):
logger.info("ControlledApplication_FailuresProcessing Event")
global dict_corrupted
global currentFamilyName
try:
fas = e.GetFailuresAccessor()
fas.DeleteAllWarnings()
fma = fas.GetFailureMessages()
for fa in fma:
logger.debug(("failure Description", fa.GetDescriptionText()))
if fa.GetSeverity() != FailureSeverity.Warning:
dict_corrupted.Add(currentFamilyName, fa.GetDescriptionText())
#if fa.GetDefaultResolutionCaption() == "Remove Constraints":
if fas.IsFailureResolutionPermitted(fa, FailureResolutionType.UnlockConstraints):
fa.SetCurrentResolutionType(FailureResolutionType.UnlockConstraints)
fas.ResolveFailure(fa)
else:
fa.SetCurrentResolutionType(FailureResolutionType.DeleteElements)
fas.ResolveFailure(fa)
e.SetProcessingResult(FailureProcessingResult.ProceedWithCommit)
except Exception as ex:
logger.exception(ex)
class FailureAdvancedHandler(IFailuresPreprocessor):
# create a dictionnary to store families with warnings
dict_Warning = Dictionary[System.String, List[System.String]]()
def __init__(self, famDoc):
self._famDoc = famDoc
def PreprocessFailures(self, failuresAccessor):
failMessages = failuresAccessor.GetFailureMessages()
if failMessages.Count == 0:
return FailureProcessingResult.Continue
transName = failuresAccessor.GetTransactionName()
try:
self.__class__.dict_Warning.Add(self._famDoc.Title, List[System.String]([m.GetDescriptionText() for m in failMessages]))
# if alert is an warn remove it
if failuresAccessor.GetSeverity() == FailureSeverity.Warning:
for currentMessage in failMessages:
failuresAccessor.DeleteWarning(currentMessage)
return FailureProcessingResult.Continue
# if alert is an error resolve it (by delete elements or by split group etc...)
elif failuresAccessor.GetSeverity() != FailureSeverity.Warning:
for currentMessage in failMessages:
if currentMessage.GetDefaultResolutionCaption() == "Remove Constraints":
failuresAccessor.SetCurrentResolutionType(FailureResolutionType.UnlockConstraints)
failuresAccessor.ResolveFailure(currentMessage)
else:
failuresAccessor.SetCurrentResolutionType(FailureResolutionType.DeleteElements)
failuresAccessor.ResolveFailure(currentMessage)
return FailureProcessingResult.ProceedWithCommit
else:
pass
except Exception as e:
logger.exception(ex)
return FailureProcessingResult.Continue
# Retrieve all families that are not system families in current doc
fam_types = UnwrapElement(IN[0])#FilteredElementCollector(projDoc).OfClass(Family)
errors = []
dict_warnings = None
dict_corrupted = Dictionary[System.String, System.String]()
delegate = System.EventHandler[FailuresProcessingEventArgs]( ControlledApplication_FailuresProcessing )
app.FailuresProcessing += delegate
for f in fam_types:
if (f.IsEditable):
currentFamilyName = f.Name
try:
TransactionManager.Instance.ForceCloseTransaction()
famDoc = projDoc.EditFamily(f)
t = Transaction(famDoc, 'Test')
t.Start()
failureOptions = t.GetFailureHandlingOptions()
handler = FailureAdvancedHandler(famDoc)
failureOptions.SetFailuresPreprocessor(handler)
t.SetFailureHandlingOptions(failureOptions)
if famDoc.IsFamilyDocument:
famManager = famDoc.FamilyManager
for familyType in famManager.Types:
famManager.CurrentType = familyType
famDoc.Regenerate()
except Exception as ex:
logger.exception(ex)
dict_corrupted.Add(currentFamilyName, str(ex))
else:
t.Commit()
t.Dispose()
famDoc.Close(False)
famDoc.Dispose()
dict_warnings = FailureAdvancedHandler.dict_Warning
app.FailuresProcessing -= delegate
OUT = dict_corrupted, dict_warnings
5 Likes
That is awesome!
Thanks for your hard work!
Mark
EDIT: Just a tiny tweak to suppress All the warnings…
if fas.IsFailureResolutionPermitted(fa, FailureResolutionType.UnlockConstraints):
fa.SetCurrentResolutionType(FailureResolutionType.UnlockConstraints)
fas.ResolveFailure(fa)
e.SetProcessingResult(FailureProcessingResult.ProceedWithCommit)
else:
fa.SetCurrentResolutionType(FailureResolutionType.DeleteElements)
fas.ResolveFailure(fa)
e.SetProcessingResult(FailureProcessingResult.ProceedWithCommit)
except Exception as ex:
3 Likes