12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- using System;
- using System.IO;
- using System.Xml;
- using SAGA.DotNetUtils;
- using SAGA.RevitMenu.ShortKey;
- using SAGA.RevitUtils;
- namespace SAGA.RevitMenu
- {
- public class ScreenMenuKeyBoardShortCut
- {
- public static void SetKeyboardShortcuts(string versionName)
- {
- try
- {
- string path = Path.Combine(Path.Combine(Environment.ExpandEnvironmentVariables(@"%appdata%\Autodesk\Revit"), versionName), "KeyboardShortcuts.xml");
- XmlDocument doc = new XmlDocument();
- if (!File.Exists(path))
- {
- File.Copy(
- Path.Combine(
- Path.Combine(AppBaseInfo.DllRunPath, "ShortKey"),
- "KeyboardShortcuts.xml"), path);
- }
- doc.Load(path);
- SetSpaceShortcuts(doc);
- doc.Save(path);
- }
- catch (Exception exception)
- {
- MessageShow.Show(exception, false, "");
- }
- }
- /// <summary>
- /// 设置放置空调的快捷键
- /// </summary>
- /// <param name="doc"></param>
- private static void SetSpaceShortcuts(XmlDocument doc)
- {
- string SpaceKey = "UKJ";
- string ASpaceKey = "UAKJ";
- ShortKeyHelper.AddShotKey(doc, "ID_OBJECTS_MEP_SPACE", SpaceKey);
- ShortKeyHelper.AddShotKey(doc, "Dialog_RoomAreaPlan_RoomTagDlgBar:Control_RoomAreaPlan_FindAllSpaces", ASpaceKey);
- string SaveKey = "SSS";
- ShortKeyHelper.AddShotKey(doc, "ID_REVIT_FILE_SAVE", SaveKey);
- }
- private static void SetOneKeyboardShortcuts(XmlDocument doc, string commandName, string className, string shortcuts, string ribbonTabName, string ribbonPanelName)
- {
- XmlElement documentElement = doc.DocumentElement;
- string str = "CustomCtrl_%CustomCtrl_%" + ribbonTabName + "%" + ribbonPanelName + "%" + className;
- string str2 = ribbonTabName + ">" + ribbonPanelName;
- string xpath = string.Format("Shortcuts/ShortcutItem[@CommandId='{0}']", str);
- XmlNode node = doc.SelectSingleNode(xpath);
- if (node == null)
- {
- XmlElement newChild = doc.CreateElement("ShortcutItem");
- newChild.SetAttribute("CommandName", commandName);
- newChild.SetAttribute("CommandId", str);
- newChild.SetAttribute("Shortcuts", shortcuts);
- newChild.SetAttribute("Paths", str2);
- documentElement.AppendChild(newChild);
- }
- else
- {
- XmlElement element3 = node as XmlElement;
- if (!element3.HasAttribute("Shortcuts"))
- {
- element3.SetAttribute("Shortcuts", shortcuts);
- }
- else if (element3.GetAttribute("Shortcuts").CompareTo(shortcuts) != 0)
- {
- element3.SetAttribute("Shortcuts", shortcuts);
- }
- if (!element3.HasAttribute("CommandName"))
- {
- element3.SetAttribute("CommandName", commandName);
- }
- else if (element3.GetAttribute("CommandName").CompareTo(commandName) != 0)
- {
- element3.SetAttribute("CommandName", commandName);
- }
- if (!element3.HasAttribute("Paths"))
- {
- element3.SetAttribute("Paths", str2);
- }
- else if (element3.GetAttribute("Paths").CompareTo(str2) != 0)
- {
- element3.SetAttribute("Paths", str2);
- }
- }
- }
- }
- }
|