How to force the DockablePane to start hidden?

How to force the DockablePane to start hidden?

Anonymous
Not applicable
2,340 Views
5 Replies
Message 1 of 6

How to force the DockablePane to start hidden?

Anonymous
Not applicable

I'm calling RegisterDockablePane in the OnStartup function of my plugin.

 

However, I'd like for the Dockable Pane to start hidden, so I can toggle the visibility from a Ribbon button.

 

But within the OnStartup function, if I try to immediately get the Pane with application.GetDockablePane(paneID), it states that the Pane is not yet created?

 

At what point / event is the Pane actually created, so I can set it to hidden with the Hide function (ideally before the user sees it)? .

 

Also, and I know this is probably a stupid question - why the hell doesn't the DockablePane class implement an IsVisible method?

0 Likes
Accepted solutions (1)
2,341 Views
5 Replies
Replies (5)
Message 2 of 6

Revitalizer
Advisor
Advisor
Accepted solution

Hi,

 

there are

 

Application.ApplictionInitialized and

ControlledApplication.ApplictionInitialized

 

RevitAPI.chm says:

"The event is raised after Revit was launched as fully initialized, including initialization of external applications."

 

Try to get your Dockable Pane just then.

 

 

Revitalizer

 

 




Rudolf Honke
Software Developer
Mensch und Maschine





Message 3 of 6

Anonymous
Not applicable

Thank you.

 

I'd actually found the ViewActivated event on the UIControlledApplication object, that seems to work for me too.

0 Likes
Message 4 of 6

ryanpdaley
Explorer
Explorer

The objective is to have the dockable panel hidden at startup.
I guess you are suggesting a method bound to the UIControlledApplication.ViewActivated event that would hide the dockable panel before the user sees it.  While this does work, it also hides the dockable panel whenever the user switches views.  Which is very undesirable.  Further, I can see the panel flash for split second before it is hidden, which seems a little unprofessional.  

public Result OnStartup(UIControlledApplication a)
{
    // Method to add Tab and Panel 
    RibbonPanel panel = RibbonPanel(a);
    if (panel.AddItem(
        new PushButtonData(Globals.ApplicationName, Globals.ApplicationName, thisAssemblyPath,
            "RevitTemplate.Show")) is PushButton button)
    {

    a.ControlledApplication.ApplicationInitialized += ControlledApplication_ApplicationInitialized1;

    a.ViewActivated += HideDockablePanel;

    return Result.Succeeded;
}

private void ControlledApplication_ApplicationInitialized(object sender, ApplicationInitializedEventArgs e)
{
    //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);
        HidePanel();
    }
    catch (Exception ex)
    {
        SimpleLog.Log(ex);
        return;
    }
    return;
}

private void HideDockablePanel(object sender, ViewActivatedEventArgs 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);
    }
}



 

0 Likes
Message 5 of 6

ryanpdaley
Explorer
Explorer

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);
    }
}
0 Likes
Message 6 of 6

ryanpdaley
Explorer
Explorer

I found a solution to the problem I identified above.

To prevent the DockablePane from being hidden whenever the user switches view.  The UIControlledApplication needs to unsubscribe from the ViewActivated event after it is hidden the first time.

private void HideDockablePanel(object sender, ViewActivatedEventArgs e)
{
    DockablePaneId id = new DockablePaneId(new Guid("{DF291951-6819-414F-8605-3A837F6972D2}"));
    try
    {
        DockablePane dockableWindow = uiControlledApp.GetDockablePane(id);
        dockableWindow.Hide();
        uiControlledApp.ViewActivated -= HideDockablePanel; 
    }
    catch (Exception ex)
    {
        SimpleLog.Log(ex);
    }
}
0 Likes