Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get a list of all the Revit Warnings

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
Anonymous
3419 Views, 10 Replies

Get a list of all the Revit Warnings

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.

Tags (2)
10 REPLIES 10
Message 2 of 11
jeremytammik
in reply to: Anonymous

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.



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 11
Anonymous
in reply to: jeremytammik

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

Message 4 of 11
FAIR59
in reply to: Anonymous

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;

            }
Message 5 of 11
Anonymous
in reply to: Anonymous

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


 

Tags (1)
Message 6 of 11
jeremytammik
in reply to: Anonymous

Use the Document.GetWarnings method:

 

https://apidocs.co/apps/revit/2019/4774613d-600a-e1b5-b5aa-f1ee3b14394c.htm

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 7 of 11
perry.swoboda
in reply to: FAIR59

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));

Message 8 of 11
schnierer.gabor
in reply to: Anonymous

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

Message 9 of 11

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 Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 10 of 11

@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));

 

Message 11 of 11
jeremy_tammik
in reply to: Anonymous

Brilliant! Thank you again. Shared on the blog for posterity:

 

https://thebuildingcoder.typepad.com/blog/2021/07/installer-list-of-failures-adjacent-rooms-and-wall... 

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report