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. In the previous part, we enhanced the custom DockablePane a bit and docked it to the ElementView window instead. In this post, let’s see how to hide the custom DockablePane and show it again.
It is very simple to hide the custom DockablePane, simply through clicking the small tiny cross icon at the right top corner of the pane, so no need to create some explicit code to force it to happen. To show it again however, it needs a bit carefully thinking.
Rather than create a new instance of the custom DockablePane, we’d better find the existing instance and show the custom DockablePane if it is still valid.
//TODO: add your code below.
DockablePane pane = CachedUiApp.GetDockablePane(ExtApp.paneId);
if (pane != null)
{
pane.Show();
}
The above code should be added to the Execute implementation of the ExtCmd class.
Another code change needs to be made is to store of the panel ID into a global variable of the ExtApp:
#region Cached Variables
public static DockablePaneId paneId;
…
#endregion
#region IExternalApplication Members
public Result OnStartup(UIControlledApplication uiApp)
{
…
//DockablePaneId paneId = new DockablePaneId(Guid.NewGuid());
paneId = new DockablePaneId(Guid.NewGuid());
…
}
That is about it. Now if the Page1 DockablePane has been hidden, it will show up again if we click the NSS tab => SimplestDockablePanel panel => ExtCmd button from the ribbon. Clicking the button multiple times won’t get any harm since the DockablePane.Show() call will handle the situation nicely. By the way, the ribbon NSS tab, the ribbon SimplestDockablePanel panel, and the ribbon ExtCmd button along with the ExtCmd command/class were are automatically generated by the Revit .NET Addin Wizard (RevitNetAddinWizard) by default.
So, we create and register the custom DockablePane at the start-up of the addin application, hide the DockablePane by manually clicking the x icon, and show the DockablePane again with the default ribbon button that is created by the Revit .NET Addin Wizard (RevitNetAddinWizard).
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.