Register command without creating (visible) button

Register command without creating (visible) button

Anonymous
Not applicable
1,209 Views
6 Replies
Message 1 of 7

Register command without creating (visible) button

Anonymous
Not applicable

I'm about to create a Command that can be accessed via shortcuts but has no (Visible) button on Ribbon, if possible.

 

Everything works fine if I create a (visible) ribbon button for the command: the command's PushButtonData.text field can be seen on "Keyboard Shortcuts" panel, I can associate a keystroke for that an pressing keys the command runs. Note that as the button is added to the ribbon, it can be seen (but I don't want to do so, this is a shortcut for more advanced/productive users and would have not much advance if user had do click on through selected panel of ribbon bar).

If I make the button invisible (RibbonItem's Visible = false) then I can assign a keystroke (shown there) but if I press that, the method doesn't run.

Note that I've checked TheBuildingCoder's articles here:
https://jeremytammik.github.io/tbc/a/1040_postcommand.htm

https://thebuildingcoder.typepad.com/blog/2013/03/whats-new-in-the-revit-2013-api.html

And haven't found a clue but maybe problem's on my side.

 

Is there any idea how to make a Command available for "Keyboard Shortcuts" without displaying it as a ribbon button?

 

Thanks in advance

0 Likes
Accepted solutions (1)
1,210 Views
6 Replies
Replies (6)
Message 2 of 7

MarryTookMyCoffe
Collaborator
Collaborator

I never did it, but I have few guess how to do it.
1) schortcuts are saved in txt files and they had refrence to a command, you could write this manualy to a file, you just need to now how to format it. Create visible button make schortcut, see what change in file, and then make it invisible and if it is gone from file, add it(or make sure that app when you start revit chek if this line exist, add when needed). This will be hard because you will need to make parser for this file and make sure you don't break anything.
2) there is this dll UIFramework(or maybe it was AdWindows.dll, google pimp my reivt. I used it to change names and image of button in production ) , that allow you to  have more options, maybe making button invisible will allow to use it, or you can make size of button so small that it is practically invisible.

3) did you try to make a new ribbon and put button there and just make ribbon invisible?
4) the most annoying way is to just put it in event that catch you when you push some buttons.

it may be a way to much work, maybe just do the same thing that add inn manager do and add this kind of buttons  in a split button in side of Add-Ins tab.
but if you success share it with us, If you can.
good luck

-------------------------------------------------------------
--------------------------------|\/\/|------------------------
do not worry it only gonna take Autodesk 5 years to fix bug
Message 3 of 7

Anonymous
Not applicable
Thanks for answering,
-I don't want to hardcode a Keyboard Shortcut (it's a lethal sin from a user perspective), so I let Your 1) and 4) guess go.
-3) was a good hint but making an invisible ribbon had the same effect as an invisible button (not working)
-I don't exactly understand what #2 is about but seems to be an overkill.
0 Likes
Message 4 of 7

RPTHOMAS108
Mentor
Mentor

I have a feeling what you want to do is not possible because the short-cuts are based on a UI location address (which panel > which button etc.).

 

What I've done in the past is create a single button for multiple shortcuts. In reality it is one short-cut to Revit but as soon as the external command is triggered you can investigate the key down events to see where to go from there i.e. if all shortcuts are prefixed with the same letter.

0 Likes
Message 5 of 7

Anonymous
Not applicable
Aha, thx.
Then it is probable that it is not possible.
Note that I want to solve a very different problem that most answers are for. (I don't want to set a shortcut at all, especially not a burnt-in one. I want to expose/register my command to Revit in a way that it is possible to assign a shortcut via the usual metod.)
0 Likes
Message 6 of 7

FAIR59
Advisor
Advisor
Accepted solution

for a keyboard shortcut to work, the button needs to be visible on a visible tab (active or non-active). Hiding a button from the user means it can't be visible on the active tab. 

Combining both requirements means the button should be placed on 2 tabs, and "hidden" when activating a tab it is placed upon.

Using the AdWindows.dll , you can implement this solution, by placing the panel with the button on an extra tab, and "hiding" the panel when the tab get activated.

Create a "standard" button and in the application.ControlledApplication.ApplicationInitialized event do the magic.

 

 

        // using  Adwin= Autodesk.Windows;
        // in OnStartup a button is created on tab "FAIR", panel "TestCommand",
        // find panel and add the panel to the Add-Ins tab

        static Adwin.RibbonPanel my_Panel = null;

        private void ControlledApplication_ApplicationInitialized(object sender, Autodesk.Revit.DB.Events.ApplicationInitializedEventArgs e)
        {
            Adwin.RibbonControl ribbon = Adwin.ComponentManager.Ribbon;
            Adwin.RibbonTab AddinTab = null;
            foreach (var tab in ribbon.Tabs)
            {
                if (tab.Title == "Add-Ins")  AddinTab = tab;    // Add-Ins tab
                if (tab.Title == "FAIR")                         
                {
                    foreach (var panel in tab.Panels)
                    {
                        if (panel.Source.Title == "TestCommand")
                        {
                            my_Panel = panel;
                            tab.Activated += MyTab_Activated;
                            tab.Deactivated += MyTab_Deactivated;
                            break;
                        }
                    }
                }
            }
            if (my_Panel == null) return;
            AddinTab.Panels.Add(my_Panel);
            AddinTab.Activated += MyTab_Activated;
            AddinTab.Deactivated += MyTab_Deactivated;
        }

        private void MyTab_Deactivated(object sender, EventArgs e)
        {
            (sender as Adwin.RibbonTab).Panels.Add(my_Panel);
        }

        private void MyTab_Activated(object sender, EventArgs e)
        {
            (sender as Adwin.RibbonTab).Panels.Remove(my_Panel);
        }

 

 

 

0 Likes
Message 7 of 7

Anonymous
Not applicable
Such a hackaround, but WORKS.
I have to confess that if You didn't provide the code I wouldn't jump into it, because the approach is so indirect.

Thanks
0 Likes