I've tried this solution, and I still get the Autodesk.Revit.Exception.ArgumentException: 'The requested dockable panel has not been created yet. parameter name: id'
This exception is thrown on my method that subscribes to the ApplicationInitialized event, when I try .GetDockablePane(id) and then .Hide().
public Result OnStartup(UIControlledApplication a)
{
uiControlledApp = a;
RibbonPanel panel = RibbonPanel(a);
if (panel.AddItem(
new PushButtonData(Globals.ApplicationName, Globals.ApplicationName, thisAssemblyPath,
"RevitTemplate.Show")) is PushButton button)
{
button.ToolTip = "Hub for finding and downloading reused materials.";
Uri uriImage = new Uri("pack://application:,,,/RevitTemplate;component/Resources/Tvinn_Logo_32px.png");
BitmapImage largeImage = new BitmapImage(uriImage);
button.LargeImage = largeImage;
}
RegisterDockablePanel();
a.ControlledApplication.ApplicationInitialized += ControlledApplication_ApplicationInitialized;
return Result.Succeeded;
}
private void RegisterDockablePanel()
{
//DockablePane needs to be registered before any Model is opened
//https://stackoverflow.com/questions/57240366/how-to-register-dockable-panel-programmatically-in-revit-api-c-sharp
DockablePaneId dpid = new DockablePaneId(new Guid("{DF291951-6819-414F-8605-3A837F6972D2}"));
try
{
_MainForm = new Ui();
uiControlledApp.RegisterDockablePane(dpid, Globals.OrganizationName, _MainForm as IDockablePaneProvider);
}
catch (Exception ex)
{
SimpleLog.Log(ex);
return;
}
return;
}
private void ControlledApplication_ApplicationInitialized(object sender, ApplicationInitializedEventArgs e)
{
DockablePaneId id = new DockablePaneId(new Guid("{DF291951-6819-414F-8605-3A837F6972D2}"));
try
{
DockablePane dockableWindow = uiControlledApp.GetDockablePane(id);
dockableWindow.Hide();
}
catch (Exception ex)
{
SimpleLog.Log(ex);
}
}