ScreenMenuKeyBoardShortCut.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System;
  2. using System.IO;
  3. using System.Xml;
  4. using SAGA.DotNetUtils;
  5. using SAGA.RevitUtils;
  6. namespace SAGA.RevitMenu.ShortKey
  7. {
  8. public class ScreenMenuKeyBoardShortCut
  9. {
  10. public static void SetKeyboardShortcuts(string versionName)
  11. {
  12. try
  13. {
  14. string path = Path.Combine(Path.Combine(Environment.ExpandEnvironmentVariables(@"%appdata%\Autodesk\Revit"), versionName), "KeyboardShortcuts.xml");
  15. XmlDocument doc = new XmlDocument();
  16. if (!File.Exists(path))
  17. {
  18. File.Copy(
  19. Path.Combine(
  20. Path.Combine(AppBaseInfo.DllRunPath, "ShortKey"),
  21. "KeyboardShortcuts.xml"), path);
  22. }
  23. doc.Load(path);
  24. SetSpaceShortcuts(doc);
  25. doc.Save(path);
  26. }
  27. catch (Exception exception)
  28. {
  29. MessageShow.Show(exception, false, "");
  30. }
  31. }
  32. /// <summary>
  33. /// 设置放置空调的快捷键
  34. /// </summary>
  35. /// <param name="doc"></param>
  36. private static void SetSpaceShortcuts(XmlDocument doc)
  37. {
  38. string SpaceKey = "UKJ";
  39. string ASpaceKey = "UAKJ";
  40. ShortKeyHelper.AddShotKey(doc, "ID_OBJECTS_MEP_SPACE", SpaceKey);
  41. ShortKeyHelper.AddShotKey(doc, "Dialog_RoomAreaPlan_RoomTagDlgBar:Control_RoomAreaPlan_FindAllSpaces", ASpaceKey);
  42. string SaveKey = "SSS";
  43. ShortKeyHelper.AddShotKey(doc, "ID_REVIT_FILE_SAVE", SaveKey);
  44. }
  45. private static void SetOneKeyboardShortcuts(XmlDocument doc, string commandName, string className, string shortcuts, string ribbonTabName, string ribbonPanelName)
  46. {
  47. XmlElement documentElement = doc.DocumentElement;
  48. string str = "CustomCtrl_%CustomCtrl_%" + ribbonTabName + "%" + ribbonPanelName + "%" + className;
  49. string str2 = ribbonTabName + "&gt;" + ribbonPanelName;
  50. string xpath = string.Format("Shortcuts/ShortcutItem[@CommandId='{0}']", str);
  51. XmlNode node = doc.SelectSingleNode(xpath);
  52. if (node == null)
  53. {
  54. XmlElement newChild = doc.CreateElement("ShortcutItem");
  55. newChild.SetAttribute("CommandName", commandName);
  56. newChild.SetAttribute("CommandId", str);
  57. newChild.SetAttribute("Shortcuts", shortcuts);
  58. newChild.SetAttribute("Paths", str2);
  59. documentElement.AppendChild(newChild);
  60. }
  61. else
  62. {
  63. XmlElement element3 = node as XmlElement;
  64. if (!element3.HasAttribute("Shortcuts"))
  65. {
  66. element3.SetAttribute("Shortcuts", shortcuts);
  67. }
  68. else if (element3.GetAttribute("Shortcuts").CompareTo(shortcuts) != 0)
  69. {
  70. element3.SetAttribute("Shortcuts", shortcuts);
  71. }
  72. if (!element3.HasAttribute("CommandName"))
  73. {
  74. element3.SetAttribute("CommandName", commandName);
  75. }
  76. else if (element3.GetAttribute("CommandName").CompareTo(commandName) != 0)
  77. {
  78. element3.SetAttribute("CommandName", commandName);
  79. }
  80. if (!element3.HasAttribute("Paths"))
  81. {
  82. element3.SetAttribute("Paths", str2);
  83. }
  84. else if (element3.GetAttribute("Paths").CompareTo(str2) != 0)
  85. {
  86. element3.SetAttribute("Paths", str2);
  87. }
  88. }
  89. }
  90. }
  91. }