Quantcast
Channel: RevitNetAddinWizard & NavisworksNetAddinWizard
Viewing all articles
Browse latest Browse all 872

Revit .NET API: Create Custom Dockable Pane (DockablePane) (pt. 4)

$
0
0

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.

In this post, let us add a button to the custom DockablePane and call the Revit Save command to save the current Revit model.

We add a button to the layout of the Page1.xaml first.

        <Button Content="Save" Height="23" Name="button1" Width="276" Click="button1_Click" />

Next, we add the following button callback and idling event handler to the code-behind file, Page1.xaml.cs:

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            ExtApp._cachedUiCtrApp.Idling += UIAppEvent_Idling_Handler;
        }

        public static void UIAppEvent_Idling_Handler(Object sender, EventArgs args)
        {
            UIApplication uiApp = sender as Autodesk.Revit.UI.UIApplication;
            if (uiApp.CanPostCommand(RevitCommandId.LookupPostableCommandId(PostableCommand.Save)))
            {
                uiApp.PostCommand(RevitCommandId.LookupPostableCommandId(PostableCommand.Save));
            }
            uiApp.Idling -= UIAppEvent_Idling_Handler;
        }

That is about it. Now we can press the F5 key to test it. This time, the Page1 DockablePane has a button besides the underlying image that was added before. When the button is clicked the Save command will be sent to Revit to execute.
  DockablePaneButtonToSave

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.


Viewing all articles
Browse latest Browse all 872

Trending Articles