Revit二次开发--事件

Revit二次开发中,事件的使用有两个步骤:
1)得到事件通知后的相应处理函数;
2)事件注册;

	//响应处理函数
	public void application_DocumentOpened(object sender,DocumentOpenedEventArgs args)
    {
        //从事件中获得文档对象
        Document doc = args.Document;
        using (Transaction trans = new Transaction(doc))
        {
            trans.Start("Edit Address");
            TaskDialog.Show("Information","事件执行中");
            //Todo...
            trans.Commit();
        }
    }
	//事件的注册
	public Result OnStartup(UIControlledApplication application)
    {
        try
        {
            //注册事件
            application.ControlledApplication.DocumentOpened += new EventHandler<DocumentOpenedEventArgs>application_DocumentOpened);
        }
        catch (Exception)
        {
            return Result.Failed;
        }
        return Result.Succeeded;
    }
	//事件注销
	 public Result OnShutdown(UIControlledApplication application)
    {
        application.ControlledApplication.DocumentOpened -= application_DocumentOpened;
        return Result.Succeeded;
    }

猜你喜欢

转载自blog.csdn.net/qq_43026206/article/details/83993573