Extract Past Warnings From Rvt file Before 2018

Extract Past Warnings From Rvt file Before 2018

Anonymous
Not applicable
467 Views
1 Reply
Message 1 of 2

Extract Past Warnings From Rvt file Before 2018

Anonymous
Not applicable

How Exactly do i retreive Rvt Saved warnings with the api ?
if not possible i have already done it using post command and the win api but revit only lets me post command Once . is it possible to Post the review warnings command more than once ?
can i retreive the warning using the Ole Storage concept ?

 

0 Likes
468 Views
1 Reply
Reply (1)
Message 2 of 2

FAIR59
Advisor
Advisor

When you use PostCommand, the PostedCommand executes after the "termination" of your addin- command, and at that point Revit has control. To execute  PostCommand multiple times, you'd have to take / get the control back from Revit.

I can see 2 ways to get the control back (there may be more)

  1. Subscribe to an Event that you know will happen during / after the execution of the PostedCommand.  (for instance the  DocumentChangedEvent)
  2. Subscribe to the FailureProcessing.

Once you have control again, you can use an ExternalEvent to interact with Revit

  

This code shows how to list the Saved Warnings on screen in an External Event.

 

    [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    public class ReVisitWarnings : IExternalCommand
    {
        public static UIApplication app;
        public static FailuresAccessor fAccessor;
        public static EventHandler<FailuresProcessingEventArgs> myHandler;
        private static ExternalEvent m_ExEvent;

        public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            app = commandData.Application;
            myHandler = new EventHandler<FailuresProcessingEventArgs>(FailuresProcessing);
            app.Application.FailuresProcessing += myHandler;

            RevitCommandId id = RevitCommandId.LookupPostableCommandId(PostableCommand.ReviewWarnings);
            app.PostCommand(id);
            return Result.Succeeded;
        }

        private void FailuresProcessing(object sender, FailuresProcessingEventArgs e)
        {
            fAccessor = e.GetFailuresAccessor();
            if (fAccessor.GetFailureMessages().Count == 0) return;

            app.Application.FailuresProcessing -= myHandler;
       
            List<FailureMessage> messageList = new List<FailureMessage>();
            foreach ( FailureMessageAccessor  fmes in fAccessor.GetFailureMessages())
            {
                messageList.Add(fmes.CloneFailureMessage());
                fAccessor.DeleteWarning(fmes);
            }

            ExternalEventWarningReview handler = new ExternalEventWarningReview(messageList);
            m_ExEvent = ExternalEvent.Create(handler);
            m_ExEvent.Raise();
            e.SetProcessingResult(FailureProcessingResult.ProceedWithRollBack);
        }

        public class ExternalEventWarningReview : IExternalEventHandler
        {
            List<FailureMessage> fMessages;
            public ExternalEventWarningReview(List<FailureMessage> messages)
            {
                fMessages = messages;
            }
            public void Execute(UIApplication app)
            {
                m_ExEvent.Dispose();
                StringBuilder sb = new StringBuilder();
                // Document doc = app.ActiveUIDocument.Document;
                foreach (FailureMessage fm in fMessages)
                {
                    sb.AppendLine(string.Format( "{0}", fm.GetDescriptionText()));
                    foreach (var id in fm.GetFailingElements())     sb.AppendLine(string.Format("   failingelement <{0}>", id));
                    foreach (var id in fm.GetAdditionalElements())    sb.AppendLine(string.Format("   additionalelements <{0}>", id));
                }
                TaskDialog.Show("External Event", sb.ToString());
            }

            public string GetName()
            {
                return "Warning-Review External Event";
            }
        }
    }
0 Likes