用于“ AIPAppStartup”的Revit SDK示例具有针对执行的“ OnShutDown”(在关闭Revit会话时)或“ OnStartup”(在启动Revit会话时)的代码的预构建部分,但是我希望能够为加载的每个文档运行代码。具体来说,我希望Revit清除与加载的特定模型关联的临时文件。

我尝试创建新结果,
公开的Autodesk.Revit.UI.Result OnLoad(UIControlledApplication应用程序),此方法不起作用。我还尝试了另一对On ****的可能性(OnOpen等),但也失败了。

是否有使用特定的“ On *****”结果可以实现我的愿望?

最佳答案

您要查找的事件是OnDocumentOpened(如果要在模型打开后运行),或者是OnDocumentOpening(如果要在模型打开之前运行)。

您将需要将事件处理程序添加到应用程序的OnStartup方法中:

public Result OnStartup(UIControlledApplication application)  {
     application.ControlledApplication.DocumentOpened += OnDocOpened;
     //Rest of your code here...
     return Result.Succeeded;
}

private void OnDocOpened(object sender, DocumentOpenedEventArgs args) {
    Autodesk.Revit.ApplicationServices.Application app = (Autodesk.Revit.ApplicationServices.Application)sender;
    Document doc = args.Document;
    //Your code here...
}


您还应该在应用程序的OnShutdown方法中删除事件处理程序:

public Result OnShutdown(UIControlledApplication application) {
    application.ControlledApplication.DocumentOpened -= OnDocOpened;
    //Rest of your code here...
    return Result.Succeeded;
}

关于c# - Revit C#运行代码“OnShutDown”和“OnStartup”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23658802/

10-09 23:25