---restore content starts---
1. Create a new Class library project, and the new WPF user Control (UserControl) in the project gets an instance named UserControl1.
The parent class of dockable windows in Revit is the page class, and also inherits the Idockablepaneprovider interface.
Therefore, the relevant place needs to be changed to the content shown in the figure.
2. Next you need to implement the Setupdockablepane () function in the interface in the hidden code to initialize the window state.
1 public void Setupdockablepane (dockablepaneproviderdata Data) 2 { 3
data.frameworkelement = this as FrameworkElement; 4 5 data.initialstate = new Dockablepanestate (); 6 Data.InitialState.DockPosition = Dockposi tion. Bottom; 7 8 }
This completes our UserControl1.
And our window will appear at the bottom.
3. Next, register a dockable window in Revit (incidentally, add a command button)
1 Static stringPath =typeof(Panel). assembly.location;2 3 PublicResult Onstartup (uicontrolledapplication application)4 {5Ribbonpanel Ribbonpanel = Application. Createribbonpanel ("window");6 7Pushbutton pushbutton = Ribbonpanel.additem (NewPushbuttondata8("DockPanel1","can be docked", Path,"dockpanel.test")) aspushbutton;9 Ten stringPageguid ="2ab776b4-b3fc-4810-8f44-ab5f1c9f5fa8"; OneGUID GUID =NewGuid (pageguid); ADockablepaneid ID =NewDockablepaneid (GUID); -UserControl1 Panel1 =NewUserControl1 (); -Application. Registerdockablepane (ID,"dockpaneltest", Panel1 asidockablepaneprovider); the - returnresult.succeeded; -}
The core approach is
1 Public void Registerdockablepane (2 dockablepaneid ID,3 string Title,4 idockablepaneprovider provider5 )
Panel1 is an example of a previously written UserControl1, UserControl1 inherits the Idockablepaneprovider interface.
4. Finally, the button command code
1 [Transaction (transactionmode.manual)]2 [Regeneration (regenerationoption.manual)]3 [Journaling (Journalingmode.nocommanddata)]4 Public classTest:iexternalcommand5 {6 7 PublicResult Execute (Externalcommanddata commanddata,ref stringmessage, ElementSet Element)8 {9 stringPageguid ="2ab776b4-b3fc-4810-8f44-ab5f1c9f5fa8";TenGUID GUID =NewGuid (pageguid); OneDockablepaneid ID =NewDockablepaneid (GUID); A -Dockablepane Panel =CommandData.Application.GetDockablePane (ID); - panel. Show (); the - returnresult.succeeded; - } -}
5. After the build is successful, write the addin file and open Revit to see the dockable window.
Revit API implements dockable windows