This project shows how to register and show/hide a DockablePane
using Revit API.
This project was generated by the ricaun.AppLoader Revit plugin.
The DockablePaneCreatorService
class implements some methods to Register
a FrameworkElement
object and Get
the DockablePane
registered in Revit.
public class App : IExternalApplication
{
public static DockablePaneCreatorService DockablePaneCreatorService;
public Result OnStartup(UIControlledApplication application)
{
DockablePaneCreatorService = new DockablePaneCreatorService(application);
DockablePaneCreatorService.Initialize();
application.ControlledApplication.ApplicationInitialized += (sender, args) =>
{
DockablePaneCreatorService.Register(DockablePage.Guid, new DockablePage());
};
return Result.Succeeded;
}
public Result OnShutdown(UIControlledApplication application)
{
DockablePaneCreatorService.Dispose();
return Result.Succeeded;
}
}
public partial class DockablePage : Page, IDockablePaneProvider, IDockablePaneDocumentProvider
{
public void SetupDockablePane(DockablePaneProviderData data)
{
data.InitialState = new DockablePaneState
{
DockPosition = DockPosition.Tabbed,
};
}
public void DockablePaneChanged(DockablePaneDocumentData data)
{
// Hide DockablePane if Document is FamilyDocument
var isFamilyDocument = data.Document?.IsFamilyDocument == true;
if (isFamilyDocument)
{
data.DockablePane.TryHide();
}
}
}
The Initialize
method is used to initialize the DockablePaneCreatorService
and the Dispose
method is used to dispose the DockablePaneCreatorService
. The Initialize
register the events Idling
and DockableFrameVisibilityChanged
.
The IDockablePaneProvider
is the Revit UI interface to gather information about a dockable pane initialization.
The IDockablePaneDocumentProvider
is the interface to detect when the DockablePaneChanged
with information about the DockablePaneId
, FrameworkElement
, Document
and DockablePane
.
To Register
a DockablePane
in Revit, you need to provide the Guid
of the DockablePane
and the Page
, the best place to do this is in the ApplicationInitialized
event.
The Register
of a DockablePane
only works before Revit finish initialize, or in the ApplicationInitialized
event.
application.ControlledApplication.ApplicationInitialized += (sender, args) =>
{
DockablePaneCreatorService.Register(DockablePage.Guid, new DockablePage());
};
To Register
a DockablePane
in Revit with a title, you need to provide the Guid
of the DockablePane
, the Page
and the title
, by default the if no title is provide the DockablePane
will be registered with title of the Page
if exists.
DockablePaneCreatorService.Register(DockablePage.Guid, "Dockable Title", new DockablePage());
To Register
a DockablePane
in Revit with a IDockablePaneProvider
, you need to provide the Guid
of the DockablePane
and the Page
with the interface IDockablePaneProvider
, by default if the Page
contain the interface that gonna be register.
DockablePaneCreatorService.Register(DockablePage.Guid, "Dockable Title", new DockablePage(), new DockablePaneProvider());
To Register
a DockablePane
in Revit with a IDockablePaneDocumentProvider
, you need to provide the Guid
of the DockablePane
and the Page
with the interface IDockablePaneDocumentProvider
, by default if the Page
contain the interface that gonna be register.
DockablePaneCreatorService.Register(DockablePage.Guid, "Dockable Title", new DockablePage(), new DockablePaneDocumentProvider());
To Get
a DockablePane
in Revit, you need to provide the Guid
of the DockablePane
.
DockablePane dockablePane = App.DockablePaneCreatorService.Get(DockablePage.Guid);
To GetFrameworkElement
of a DockablePane
in Revit, you need to provide the Guid
of the DockablePane
.
FrameworkElement frameworkElement = App.DockablePaneCreatorService.GetFrameworkElement(DockablePage.Guid);
The DockablePaneExtension
class implements some extensions methods to TryShow
, TryHide
, TryGetTitle
and TryIsShown
the DockablePane
registered in Revit.
The DockablePaneService
class implements some methods to Register
and Get
the DockablePane
registered in Revit.
To Register
a DockablePane
in Revit, you need to provide the Guid
of the DockablePane
and the Page
with the interface IDockablePaneProvider
.
The Register
of a DockablePane
only works before Revit finish initialize, or in the ApplicationInitialized
event.
public class App : IExternalApplication
{
public static DockablePaneService DockablePaneService;
public Result OnStartup(UIControlledApplication application)
{
DockablePaneService = new DockablePaneService(application);
application.ControlledApplication.ApplicationInitialized += (sender, args) =>
{
DockablePaneService.Register<DockablePage>(DockablePage.Guid);
};
return Result.Succeeded;
}
public Result OnShutdown(UIControlledApplication application)
{
return Result.Succeeded;
}
}
To Get
a DockablePane
in Revit, you need to provide the Guid
of the DockablePane
or the Page
registerd.
DockablePane dockablePane = App.DockablePaneService.Get(DockablePage.Guid);
or
DockablePane dockablePane = App.DockablePaneService.Get<DockablePage>();
This method gonna return null
if the DockablePane
is not registered.
- Download and install RevitAddin.Dockable.Example.exe
Video in english about this project.
This project is licensed under the MIT Licence.
Do you like this project? Please star this project on GitHub!