简介
如何在 Revit 里面用 API 实现一个类似 “属性” 和项目浏览器的可停靠窗口?
左边为系统的可停靠窗口,右边是自定义的可停靠窗口。
实现
非必须用 IExternalApplication
,可以看自己的需求,代码摘自官方文档。
要做一个自定义可停靠窗口,入口在UIControlledApplication.RegisterDockablePane
。
public class ExternalApp : IExternalApplication
{
public Result OnShutdown(UIControlledApplication application)
{
return Result.Succeeded;
}
public Result OnStartup(UIControlledApplication application)
{
// Create our pane provider and register it with the application
PaneProvider prov = new PaneProvider();
DockablePaneId id = new DockablePaneId(Guid.NewGuid());
application.RegisterDockablePane(id, "test", prov);
return Result.Succeeded;
}
}
PaneProvider
为用户自定义,可以在其中设置可停靠窗口的内容。
这里的 Page
即是 System.Windows.Controls.Page
,即微软 WPF 类库成员。
//
// Provider class called by Revit to provide information about the pane
// to embed.
//
public class PaneProvider : IDockablePaneProvider
{
public void SetupDockablePane(DockablePaneProviderData data)
{
Page page = new Page();
data.FrameworkElement = new Page();
}
}