【发布时间】:2021-02-17 08:07:59
【问题描述】:
我一直在尝试创建一个 Revit 插件,该插件允许用户查看存储在远程服务器上本地版本文件的问题。它应该从服务器上存储的数据创建一个新的 3D 透视图,并在 Revit 中打开它。但是,每当我尝试运行它时,都会收到异常警告:
Exception thrown: 'Autodesk.Revit.Exceptions.InvalidOperationException' in RevitAPIUI.dll
An unhandled exception of type 'Autodesk.Revit.Exceptions.InvalidOperationException' occurred in RevitAPIUI.dll
Attempting to create an ExternalEvent outside of a standard API execution
我想我模糊地理解这意味着什么,但我不确定究竟需要更改什么来修复它。我正在定义一个自定义 ExternalEventHandler 并实现它的 Execute 方法:
class CameraEventHandler : IExternalEventHandler
{
Issue issue;
int i;
public CameraEventHandler(Issue issue, int index)
{
this.issue = issue;
this.i = index;
}
public void Execute(UIApplication app)
{
Document doc = app.ActiveUIDocument.Document;
using (Transaction t = new Transaction(doc, "CameraTransaction"))
{
t.Start();
...
//Irrelevant code to set camera position programmatically
...
t.Commit();
}
}
public string GetName()
{
return "Camera event handler";
}
}
然后在我的一个 WPF 表单中,我创建一个 ExternalEvent 并调用 Raise 方法:
private void RevitViewButton_Click(object sender, RoutedEventArgs e)
{
CameraEventHandler handler = new CameraEventHandler(issue, issueIndex);
ExternalEvent cameraEvent = ExternalEvent.Create(handler);
cameraEvent.Raise();
}
但是,当它到达 ExternalEvent.Create 方法时会抛出异常。
编辑:我觉得值得一提的是,我正在使用的 WPF 应用程序是作为 Revit 插件启动的。
【问题讨论】:
标签: c# wpf event-handling revit-api