Revit .NET has provided the DockablePane API since version 2014. In this series of posts, we are going to explore the Revit DockablePane .NET API step by step.
In the first part, we created the simplest custom DockablePane to get the basic idea first about the DockablePane API. After that, we enhanced the custom DockablePane a bit and docked it to the ElementView window and created some code to show the custom DockablePane back in case it has been hidden. We also added a button to the custom DockablePane which will call the Revit Save command to save the current Revit model when being clicked.
Previously, we listed out some information about the custom DockablePane but found out the hosted WPF Page was not accessible from the DockablePane API itself. The limitation made the information listed out there not sufficient enough for programming purpose.
In this post, we are going to work around it, at least for our custom DockablePane of concern.
Declare one more cached variable in the ExtApp:
public static Dictionary<DockablePaneId, DockablePaneProviderData> CachedPaneData;
Then cache both the DockablePaneId and the DockablePaneProviderData of the custom DockablePane of concern in the SetupDockablePane() method of the IDockablePaneProvider interface.
if (ExtApp.CachedPaneData == null)
ExtApp.CachedPaneData = new Dictionary<DockablePaneId, DockablePaneProviderData>();
ExtApp.CachedPaneData[ExtApp.paneId] = data;
Now enhance the button callback as follows:
private void button2_Click(object sender, RoutedEventArgs e)
{
string msg = "Information about the DockablePane:\n";
DockablePane pane = ExtApp._cachedUiCtrApp.GetDockablePane(ExtApp.paneId);
if (pane != null)
{
msg += "\nTitle: " + pane.GetTitle();
msg += "\nType: " + pane.GetType();
msg += "\nId: " + pane.Id.Guid.ToString();
msg += "\nIsValie: " + pane.IsValidObject;
DockablePaneProviderData data = ExtApp.CachedPaneData[ExtApp.paneId];
msg += "\nDockPosition: " + data.InitialState.DockPosition;
msg += string.Format("\nFloatingRectangle: ({0},{1}) - ({2},{3})", data.InitialState.FloatingRectangle.Left, data.InitialState.FloatingRectangle.Top, data.InitialState.FloatingRectangle.Right, data.InitialState.FloatingRectangle.Bottom);
msg += "\nTabBehind: " + data.InitialState.TabBehind.Guid.ToString();
msg += "\nActualHeight: " + data.FrameworkElement.ActualHeight;
msg += "\nActualWidth: " + data.FrameworkElement.ActualWidth;
msg += "\nAllowDrop: " + data.FrameworkElement.AllowDrop;
msg += "\nFlowDirection: " + data.FrameworkElement.FlowDirection;
msg += "\nHeight: " + data.FrameworkElement.Height;
msg += "\nWidth: " + data.FrameworkElement.Width;
msg += "\nMargin: " + data.FrameworkElement.Margin;
}
System.Windows.Forms.MessageBox.Show(msg);
}
That is about it. Now we can press the F5 key to test it. This time, the information about the DockablePanel is comprehensive.
The FloatingRectangle is strangly reported as double (0, 0). It might be that no default values were provided to the stucture during the creation of the custom DockablePane or simply indicating an issue somewhere.
Revit Addin Wizard (RevitAddinWizard) provides various wizards, coders and widgets to help program Revit addins. It can be downloaded from the Download link at the bottom of the blog index page.