Get a list of all Revit warnings in a hierarchy

Get a list of all Revit warnings in a hierarchy

Anonymous
Not applicable
1,118 Views
2 Replies
Message 1 of 3

Get a list of all Revit warnings in a hierarchy

Anonymous
Not applicable

Hello all,

 

I'm trying to read all Revit-warning by using the following code.

 

 public static List<string> GetRevitWarningList(Document doc, bool isEmptyList = false)
        {
            if (WarningList != null && WarningList.Count > 0 && !isEmptyList) return WarningList;


            WarningList = new List<string>();
            FailureDefinitionRegistry failureReg =
                Autodesk.Revit.ApplicationServices.Application.GetFailureDefinitionRegistry();
            StringBuilder sb = new StringBuilder();
            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()));

                        WarningList.Add(_acc.GetDescriptionText());


                        if (_acc.GetDescriptionText().Contains("Ref Plane is slightly off axis and may cause inaccuracies"))
                        {
// Do something, } } } catch { } } return WarningList; }

However, I'm unable to find the parent text of these warnings like it show in the Revit warning window (please see the image below). I'm wondering if there is any way to get the description-text of their parent and get the list of their child warnings in a nice hierarchical structure.

 

warnings.PNG

 

 

 

0 Likes
Accepted solutions (1)
1,119 Views
2 Replies
Replies (2)
Message 2 of 3

jeremytammik
Autodesk
Autodesk
Accepted solution
Message 3 of 3

Anonymous
Not applicable

Thank you @jeremytammik for sharing the solution. Yes, it is the same question that I have asked in other thread too. Actually, I was running on the deadline, thought asking the same question twice might get developers attention. 

 

I'm downloading the Revit 2018 SDK, excited to use new features of the API. Thanks

0 Likes