Revit API - freezeing / hiding Buttons

Revit API - freezeing / hiding Buttons

Julian.Wandzilak
Advocate Advocate
481 Views
5 Replies
Message 1 of 6

Revit API - freezeing / hiding Buttons

Julian.Wandzilak
Advocate
Advocate

I made myself a quick method which disable panels:

public static void DisablePanels(UIApplication application, string ribbonName, List<string> listOfPanels)
{
    List<RibbonPanel> panels = application.GetRibbonPanels(ribbonName);
    foreach (RibbonPanel p in panels)
    {
        if (listOfPanels.Contains(p.Name))
        {
            p.Enabled = false;
            p.Visible = false;

        }
    }
}

 

And I am thinking about using  RibbonPanel.Enabled  or RibbonPanel.Visible.

RibbonPanel.Enabled - if sets to false it will freeze the buttons in a selected panel, but you will be able to use them with your keyboard shortcuts. 

RibbonPanel.Visible - if sets to false it will completly hide the buttons from the ribbon (and you will not be able to use them with keyboard shortcuts)

 

Is there a way to freeze the buttons and lock them from being used? I want to use it in my Entitlement check - > using "visible" works but empty ribbon looks stupid 😉

blog: w7k.pl more about me: Linkedin Profile
My add-ins for Revit: Drafter(180+ scripts) & Leveler
0 Likes
482 Views
5 Replies
Replies (5)
Message 2 of 6

bo60vdx07
Participant
Participant

-

0 Likes
Message 3 of 6

ricaun
Advisor
Advisor

@Julian.Wandzilak wrote:

RibbonPanel.Enabled - if sets to false it will freeze the buttons in a selected panel, but you will be able to use them with your keyboard shortcuts. 😉


Interesting I didn't know that. I supposed the button is disabled as well.

 

Did you try to disable the RibbonButton instead of the RibbonPanel to check if is possible to execute the command with a shortcut? I guess with the button disabled the command is not executed.

 

You should use the IExternalCommandAvailability Interface to control if the user can or cannot execute the command.

 

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

Message 4 of 6

Julian.Wandzilak
Advocate
Advocate

Thanks for help!

 

I tried with RibbonItem:

 

foreach (RibbonItem i in p.GetItems())
{
i.Enabled = false;
}

 

and it freezes them, but you can still use them with shortcuts. Later I tried to cast them to RibbonButtons and the behaviour was the same.

 

I will try IExternalCommandAvailability.

blog: w7k.pl more about me: Linkedin Profile
My add-ins for Revit: Drafter(180+ scripts) & Leveler
0 Likes
Message 5 of 6

ricaun
Advisor
Advisor

I tested to disable the button and works like interested, I was not able to execute the command with shortcut, Revit throw a sound.

 

if you put the button in the quick access toolbar is possible to see if the button is available or not, if you hide de panel or disable the panel the button can still be executed in the quick access toolbar.

 

Kinda make sense, does not matter what panel the button is located, if the RibbonButton is not disable the user can execute.

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

Message 6 of 6

Julian.Wandzilak
Advocate
Advocate

Thanks for testing! I was almost ready to surrender (hide them), but your post made me think about it again.

And I figured it out. A code below:

public static void DisablePanels(UIApplication application, string ribbonName, List<string> listOfPanels)
{
    List<RibbonPanel> panels = application.GetRibbonPanels(ribbonName);
    foreach (RibbonPanel p in panels)
    {
        if (listOfPanels.Contains(p.Name))
        {
            p.Enabled = false;

            foreach (RibbonItem i in p.GetItems())
            {
                i.Enabled = false;

                if (i is SplitButton)
                {
                    foreach (var t in ((SplitButton)i).GetItems())
                    {
                        t.Enabled = false;
                    }
                }
                //Other Button Types if necessery  
            }
        }
    }
}

As you can see, I added the second iteration thought the split button. It makes sense that I have to disable also items inside it.

blog: w7k.pl more about me: Linkedin Profile
My add-ins for Revit: Drafter(180+ scripts) & Leveler
0 Likes