首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Revit同步事件

Revit同步事件
EN

Stack Overflow用户
提问于 2019-02-05 00:05:45
回答 1查看 274关注 0票数 1

从这个开始。https://github.com/jeremytammik/RevitLookup/blob/master/CS/EventTrack/Events/ApplicationEvents.cs

我正在尝试为同步事件添加事件侦听器。下面的代码抛出一个错误,指出m_app为空。Revit正在启动时,我是否可以不订阅此活动?

我以前用application.ViewActivated += ....就能做到这一点。我想知道这是否与DB与UI驱动的事件有关,以及它们何时被允许订阅?我就是不知道。

代码语言:javascript
复制
  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");
        }

    }
}

下面是更新后的代码,反映了我对第一个答案的响应。加载文档时,将打开消息框。当我尝试初始化同步事件处理程序时,没有抛出任何错误,但是,在同步事件之前或之后,两个消息框都没有打开。

代码语言:javascript
复制
  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

代码语言:javascript
复制
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");
        }

    }

}
EN

回答 1

Stack Overflow用户

发布于 2019-02-05 03:24:56

试一试

代码语言:javascript
复制
application.ControlledApplication.DocumentSynchronizingWithCentral += new EventHandler<DocumentSynchronizingWithCentralEventArgs>(m_app_DocumentSavingToCentral)

在您的OnStartup()方法中。

调用失败,因为实例成员m_app已初始化为null。

可以从OnStartup的参数访问引发DocumentSynchronizingWithCentralEventArgsUIApplication.ControlledApplication对象。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54519965

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档