How to force the DockablePane to start hidden?

How to force the DockablePane to start hidden?

Anonymous
適用対象外
2,400件の閲覧回数
5件の返信
メッセージ1/6

How to force the DockablePane to start hidden?

Anonymous
適用対象外

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 件のいいね
解決済み
2,401件の閲覧回数
5件の返信
返信 (5)
メッセージ2/6

Revitalizer
Advisor
Advisor
解決済み

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





メッセージ3/6

Anonymous
適用対象外

Thank you.

 

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

0 件のいいね
メッセージ4/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 件のいいね
メッセージ5/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 件のいいね
メッセージ6/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 件のいいね