How to disable and enable the customized shortcuts in Revit 2014

How to disable and enable the customized shortcuts in Revit 2014

Anonymous
Not applicable
1,101 Views
11 Replies
Message 1 of 12

How to disable and enable the customized shortcuts in Revit 2014

Anonymous
Not applicable

Hi,

 

I have to disable and enable the customized shortcuts assigned to the specified command .

 

e.g Let's say I have a document A and B opened in the revit.When A document is active,I want that customized shortcut for the paste command should be enabled and when I switch to the document B ,customized shortcut for the paste command should be disabled.

 

Again when I switch to the document A,customized shortcut for the paste command should be enabled.

void UpdateShortcuts()

{

            Dictionary<string, ShortcutItem> allCommands = ShortcutsHelper.Commands;
            var map = ShortcutsHelper.LoadShortcuts();
         
            Dictionary<string, ShortcutItem> updateShortcust = new Dictionary<string, ShortcutItem>();
           
   
            foreach (string cmdId in CmdIdsForRibbonMenuItems)
            {
                if (!string.IsNullOrEmpty(cmdId)
                    && .DisabledRibbonItemCmdIds.Contains(cmdId))
                {
                    if (map.ContainsKey(cmdId))
                    {
                     
                        map[cmdId].Shortcuts.Clear();
                        var shortCutItem = map[cmdId];
                        updateShortcust.Add(cmdId, shortCutItem);
                    }
                  
                }

                //test
                if (!string.IsNullOrEmpty(cmdId)
                  && mRevitContext.ApplicationSettings.EnabledRibbonItemCmdIds.Contains(cmdId))
                {
                    if (map.ContainsKey(cmdId))
                    {
                     

                        var shortCutItem = map[cmdId];
                        updateShortcust.Add(cmdId, shortCutItem);
                    }
                
                }
               
            }

            UIFrameworkServices.KeyboardShortcutService.applyShortcutChanges(updateShortcust);

 

}

 

With this approach,it disables the customized shortcut but when we enable it as above I add a shortcut from the map and again applyshortcutchanges,it does not enable it.

 

 

Your help will be much appreciated.

 

Thanks,

ACAD_VINOD

 

 

0 Likes
1,102 Views
11 Replies
Replies (11)
Message 2 of 12

jeremy_tammik
Alumni
Alumni

Hi.

 

You definitely earn extra points for an especially imaginative and unique request.

 

I do not believe that the product offers any support out of the box for this kind of functionality.

 

Normally, people want their user interface to be more uniform and predictable, not less so.

 

One area that you can look at is the external command availability class:

 

http://thebuildingcoder.typepad.com/blog/2010/04/revitaddinutility.html

 

The External Command Availability Interface IExternalCommandAvailability

 

If you wish, you can use it to switch any given command back and forth between available and unavailable every time the document switches, or on even and uneven days of the month, even and uneven minutes of the hour, depending on the character count of the current user's last name, or whatever else you like. 

 

I hope this helps.

 

Best regards,

 

Jeremy

 

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 12

Anonymous
Not applicable

Hi Jeremy,

 

Thanks for the suggestion,that's a very good suggestion.I Just wanted to ask you whether the suggestion which you have suggested can be used for the default Revit commands or we can use that approach for only external commands.

 

Thanks for the help.

Vinod

0 Likes
Message 4 of 12

jeremytammik
Autodesk
Autodesk

Dear Vinod,

 

I have not looked at it for years now...

 

I believe it works for all commands.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 5 of 12

Anonymous
Not applicable

Hi Jeremy,

 

I have tried the approach for the IExternalCommandAvailability but this works only for the ExternalCommand.

 

This does not work for the default command.

 

Can we use the command binding canexecute to disable the command when command will be executed by shortcut.

 

Or is there any other way by which I can extend the existing command behaviour? and then I can write a availability class for that command?

 

Or is there any other suggestion ,pls suggest.

 

Thanks for the help.

 

Vinod

0 Likes
Message 6 of 12

matthew_taylor
Advisor
Advisor
Hi Vinod,
How about we take a step back and you let us know what you're trying to achieve? We may be able to find a workflow that achieves the same thing.

Cheers,

-Matt

Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 7 of 12

Anonymous
Not applicable

Hi,

 

My requirement is as follows:

 

I have to control operations performed based on certain conditions .So I have to enable and disable commands in revit.But these commands should  disable by all the way, So if I block the ribbon Item of the Publish Ribbon Item from the application menu Or say Synchronize with the central Ribbon Item, the UI of the Ribbon Item is disabled but this does not disable the customized shortcut for this command.

 

 

Thanks for your help.

Vinod

 

 

0 Likes
Message 8 of 12

matthew_taylor
Advisor
Advisor
Hi Vinod,
I understand what you're trying to do, just not why you would want to do it. Can you explain why you would want that, so perhaps we can find another way to achieve it?

Cheers,

-Matt

Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 9 of 12

Anonymous
Not applicable

Hi Matt,

 

I am trying to build a functionality which controls the permitted operations for the documents opened in Revit.

 

Thanks,

Vinod

 

 

0 Likes
Message 10 of 12

matthew_taylor
Advisor
Advisor

Hi Vinod,

Yes. But why? (Yes, I know I sound like a repetitive three-year-old!)

I understand how you're trying to solve the method that you have come up with. But, why do you want to do that? What is the whole story of what you're trying to do. Start with your initial problem, so that perhaps we can find an alternative solution.

 

Cheers,

 

-Matt


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
Message 11 of 12

Anonymous
Not applicable

Hi Matt,

 

The whole story behind developing this functionality is in my office,operations like edit family is not allowed for all users.

 

Thanks,

Vinod

0 Likes
Message 12 of 12

jeremytammik
Autodesk
Autodesk

You can install an add-in that disables built-in Revit commands by redefining them.

 

The add-in can be programmed so that is aborts loading for certain users, and not for others.



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder