ScreenMenuKeyBoardShortCut.cs 3.7 KB

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