Skip to content

ricaun-io/RevitAddin.Dockable.Example

Repository files navigation

RevitAddin.Dockable.Example

Revit 2019 Visual Studio 2022 Nuke License MIT Build

This project shows how to register and show/hide a DockablePane using Revit API.

This project was generated by the ricaun.AppLoader Revit plugin.

DockablePaneCreatorService

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();
        }
    }
}

Initialize / Dispose

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.

IDockablePaneProvider

The IDockablePaneProvider is the Revit UI interface to gather information about a dockable pane initialization.

IDockablePaneDocumentProvider

The IDockablePaneDocumentProvider is the interface to detect when the DockablePaneChanged with information about the DockablePaneId, FrameworkElement, Document and DockablePane.

Register

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());
};

Register with title

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());

Register with IDockablePaneProvider

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());

Register with IDockablePaneDocumentProvider

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());

Get

To Get a DockablePane in Revit, you need to provide the Guid of the DockablePane.

DockablePane dockablePane = App.DockablePaneCreatorService.Get(DockablePage.Guid);

GetFrameworkElement

To GetFrameworkElement of a DockablePane in Revit, you need to provide the Guid of the DockablePane.

FrameworkElement frameworkElement = App.DockablePaneCreatorService.GetFrameworkElement(DockablePage.Guid);

Extensions

The DockablePaneExtension class implements some extensions methods to TryShow, TryHide, TryGetTitle and TryIsShown the DockablePane registered in Revit.

DockablePaneService

The DockablePaneService class implements some methods to Register and Get the DockablePane registered in Revit.

Register

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;
    }
}

Get

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.

Installation

RevitAddin.Dockable.Example

RevitAddin.Dockable.Example

Video

Video in english about this project.

VideoIma1 VideoIma2

License

This project is licensed under the MIT Licence.


Do you like this project? Please star this project on GitHub!