Событие Revit Synchronization - PullRequest
       2

Событие Revit Synchronization

0 голосов
/ 04 февраля 2019

Начиная с этого ... https://github.com/jeremytammik/RevitLookup/blob/master/CS/EventTrack/Events/ApplicationEvents.cs

Я пытаюсь добавить прослушиватель событий для события синхронизации.код ниже выдает ошибку, утверждающую, что m_app имеет значение null.Могу ли я не подписаться на это событие во время запуска Revit?

Я мог сделать это раньше с application.ViewActivated += .....Мне интересно, это как-то связано с событиями, связанными с БД и пользовательским интерфейсом, и когда им разрешено подписываться?Я просто не знаю.

  namespace RevitModelHealth
{
    public class checkHealth : IExternalApplication
    {
        // Document doc;
        static public Autodesk.Revit.ApplicationServices.Application m_app = null;

        public Result OnShutdown(UIControlledApplication application)
        {
            return Result.Succeeded;
        }

        public Result OnStartup(UIControlledApplication application)
        {

            m_app.DocumentSynchronizingWithCentral += new EventHandler<DocumentSynchronizingWithCentralEventArgs>(m_app_DocumentSavingToCentral);
            return Result.Succeeded;
        }

        void m_app_DocumentSavingToCentral(object sender, Autodesk.Revit.DB.Events.DocumentSynchronizingWithCentralEventArgs e)
        {
            MessageBox.Show("asd","asd");
        }

    }
}

Вот обновленный код, отражающий мой ответ на первый ответ.Окно сообщения открывается при загрузке документа.При попытке инициализировать обработчики событий синхронизации не выдается никаких ошибок, однако ни одно из окон сообщений не открывается до или после события синхронизации.

  public class checkHealth : IExternalApplication
    {
        // Document doc;
        static public Autodesk.Revit.ApplicationServices.Application m_app;


        public Result OnShutdown(UIControlledApplication application)
        {
            return Result.Succeeded;
        }

        public Result OnStartup(UIControlledApplication application)
        {
            application.ControlledApplication.DocumentOpened += new EventHandler<DocumentOpenedEventArgs>(app_DocOpened);
            return Result.Succeeded;
        }

        public void app_DocOpened(object sender, DocumentOpenedEventArgs args)
        {
            MessageBox.Show("asd","asd");

            m_app.DocumentSynchronizingWithCentral += new EventHandler<DocumentSynchronizingWithCentralEventArgs>(m_app_DocumentSavingToCentral);
            m_app.DocumentSynchronizedWithCentral += new EventHandler<Autodesk.Revit.DB.Events.DocumentSynchronizedWithCentralEventArgs>(m_app_DocumentSavedToCentral);
        }

        void m_app_DocumentSavingToCentral(object sender, Autodesk.Revit.DB.Events.DocumentSynchronizingWithCentralEventArgs e)
        {
            MessageBox.Show("sync", "sync");
        }

        void m_app_DocumentSavedToCentral(object sender, Autodesk.Revit.DB.Events.DocumentSynchronizedWithCentralEventArgs e)
        {
            MessageBox.Show("Doone", "Done");
        }
    }

это сработало .... Во многом благодаряПример проекта SDK EventsMonitor

namespace RevitModelHealth
{
    public class checkHealth : IExternalApplication
    {


        public Result OnShutdown(UIControlledApplication application)
        {
            return Result.Succeeded;
        }

        public Result OnStartup(UIControlledApplication application)
        {
            application.ControlledApplication.DocumentSynchronizingWithCentral += new EventHandler<DocumentSynchronizingWithCentralEventArgs>(app_syncStart);
            application.ControlledApplication.DocumentSynchronizedWithCentral += new EventHandler<DocumentSynchronizedWithCentralEventArgs>(app_syncOver);
            return Result.Succeeded;
        }

        public void app_syncStart(object o ,DocumentSynchronizingWithCentralEventArgs args)
        {
            MessageBox.Show("","Stasrting");
        }

        public void app_syncOver(object o,DocumentSynchronizedWithCentralEventArgs args)
        {
            MessageBox.Show("", "Over");
        }

    }

}

1 Ответ

0 голосов
/ 04 февраля 2019

Попробуйте

application.ControlledApplication.DocumentSynchronizingWithCentral += new EventHandler<DocumentSynchronizingWithCentralEventArgs>(m_app_DocumentSavingToCentral)

в вашем методе OnStartup ().

Вызов не удался, поскольку элемент экземпляра m_app инициализирован нулевым значением.

Приложение UIApplication.ControlledApplication объект, который вызывает DocumentSynchronizingWithCentralEventArgs , доступен из параметра для OnStartup.

...