Is it possible to get a list of all the Revit warnings? The warnings that will appear in the Warning Inquiry window are warnings that appear in the model. However, I want the entire list. I want to find around 100 warning types and do not want 100 if statements, which would be required using the code I found:
void ControlledApplication_FailuresProcessing(object sender, Autodesk.Revit.DB.Events.FailuresProcessingEventArgs e) { FailuresAccessor accessor = e.GetFailuresAccessor(); IList<FailureMessageAccessor> messages = accessor.GetFailureMessages(); foreach (FailureMessageAccessor failure in messages) { FailureDefinitionId failId = failure.GetFailureDefinitionId(); if (failId == BuiltInFailures.OverlapFailures.WallsOverlap) { TaskDialog.Show("Deleting Failure", failure.GetDescriptionText()); accessor.DeleteWarning(failure); } } }
Ideally, I would just like a complete list of Warning Error Messages, then I can add the ones I care about finding to a list and use List.Contains.
Solved! Go to Solution.
Solved by FAIR59. Go to Solution.
Yes. This is one important wish list item that we hope to implement for the next major release of Revit. So no solution right now, but coming up anon. As always, no promises on any future stuff, but keeping my fingers crossed that our plans will come to full fruition.
Hi Jeremy,
Is it something you have a list, in some of the inner documentation?
I basically want to highlight the key warnings then scan through the HTML output to find ones that are of interest.
Thanks
Graham
Hi Graham,
You can use the FailureDefinitionRegistry to find the failures , and using reflection you can distinguish between system defined and user-defined failures.
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] public class ListFailures : IExternalCommand { StringBuilder sb = new StringBuilder(); public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uiDoc = commandData.Application.ActiveUIDocument; Document document = uiDoc.Document; Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application; FailureDefinitionRegistry failureReg = Autodesk.Revit.ApplicationServices.Application.GetFailureDefinitionRegistry(); Type _type = typeof(BuiltInFailures); Type[] _nested = _type.GetNestedTypes(System.Reflection.BindingFlags.Public); Dictionary<Guid, Type> _dict = new Dictionary<Guid, Type>(); string _ClassName = string.Empty; foreach (Type nt in _nested) { try { _ClassName = nt.FullName.Replace('+', '.'); sb.AppendLine(string.Format("#### {0} ####", _ClassName)); foreach (System.Reflection.PropertyInfo pInfo in nt.GetProperties()) { System.Reflection.MethodInfo mInfo = pInfo.GetGetMethod(); FailureDefinitionId res = mInfo.Invoke(nt, null) as FailureDefinitionId; if (res == null) continue; if (_dict.ContainsKey(res.Guid)) continue; _dict.Add(res.Guid, nt); FailureDefinitionAccessor _acc = failureReg.FindFailureDefinition(res); if (_acc == null) continue; sb.AppendLine(string.Format(" * {0} <{1}> {2}", _acc.GetId().Guid, _acc.GetSeverity(), _ClassName)); sb.AppendLine(string.Format(" {0}", _acc.GetDescriptionText())); } } catch { } } _ClassName = "user-defined"; sb.AppendLine(string.Format("#### {0} ####", _ClassName)); foreach (FailureDefinitionAccessor _acc in failureReg.ListAllFailureDefinitions()) { Type DefType = null; _dict.TryGetValue(_acc.GetId().Guid,out DefType); if (DefType != null) continue; // failure already listed sb.AppendLine(string.Format(" * {0} <{1}> {2}", _acc.GetId().Guid, _acc.GetSeverity(), _ClassName)); sb.AppendLine(string.Format(" {0}", _acc.GetDescriptionText())); } TaskDialog.Show("res", sb.ToString()); return Result.Succeeded; }
Hi sir,
even mine dought is the same, m also looking for all the possible warnings that revit generates, but unfortunately m not so good in understanding the programming languages. So if you succeeded in finding the solution, will you please share the same with me.
Regards
M. Juned
@Anonymous wrote:Hi Jeremy,
Is it something you have a list, in some of the inner documentation?
I basically want to highlight the key warnings then scan through the HTML output to find ones that are of interest.
Thanks
Graham
Use the Document.GetWarnings method:
https://apidocs.co/apps/revit/2019/4774613d-600a-e1b5-b5aa-f1ee3b14394c.htm
Cheers,
Jeremy
Thanks! I have been having trouble trying to match the returned FailureDefinitionId to an actual BuiltInFailure I could handle. One small improvement is to also add the property name to your list.
sb.AppendLine(string.Format(" * {0} <{1}> {2}", _acc.GetId().Guid, _acc.GetSeverity(), _ClassName + "." + pInfo.Name));
Using the awesome code from @FAIR59 and @perry.swoboda here is a spreadsheet containing the BuiltInFailures for Revit 2022, their Severity, Classname, Guid and Description. Might come handy.
https://docs.google.com/spreadsheets/d/12glULCZL_yJkq7ko_vI-gEHu69dUIoiCRnmvdLpIoSU
Looks like just what the doctor ordered. Thank you very much for sharing that!
Did you use the code above as is or make any interesting modifications that might be worth while sharing as well, in case people would like to create their own versions?
@jeremy_tammik it is a pleasure. Feels good giving back to the community, which already provided me so much.
Yes I made some minor modifications to the code. Cleaned newline characters from the Descriptions. Played around with the AppendLine rows, merged into a single command. My goal was to return a string which is easier to parse in a spreadsheet.
Nothing interesting in my opinion.
string cleanedDescription = _acc.GetDescriptionText().Replace("\n", "").Replace("\r", "");
sb.AppendLine(string.Format("{0};{1};{2};{3}", _acc.GetSeverity(), _ClassName + "." + pInfo.Name, _acc.GetId().Guid, cleanedDescription));
Brilliant! Thank you again. Shared on the blog for posterity:
Can't find what you're looking for? Ask the community or share your knowledge.