RevitUIUtils.cs 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using Autodesk.Windows;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace LRH.Tool.RevitUI
  9. {
  10. /// <summary>
  11. /// RevitUI操作相关
  12. /// </summary>
  13. public class RevitUIUtils
  14. {
  15. /// <summary>
  16. /// 收集CommandIds
  17. /// </summary>
  18. /// <returns></returns>
  19. public static StringBuilder CollectCommandIds()
  20. {
  21. RibbonControl control = ComponentManager.Ribbon;
  22. StringBuilder builder = new StringBuilder();
  23. foreach (var currentTab in control.Tabs)
  24. {
  25. foreach (var currentPanel in currentTab.Panels)
  26. {
  27. foreach (var item in currentPanel.Source.Items)
  28. {
  29. //if(!(item is RibbonCommandItem||item is RibbonCheckBox))
  30. //{
  31. // continue;
  32. //}
  33. if(item is RibbonListButton listButton)
  34. {
  35. foreach (var currentItem in listButton.Items)
  36. {
  37. if (currentItem.Id == "ID_TOGGLE_PROPERTIES_PALETTE")
  38. {
  39. }
  40. builder.Append(string.Format("【{0}】", currentTab.Title));
  41. builder.Append("→");
  42. builder.Append(string.Format("【{0}】", currentPanel.Source.Title));
  43. builder.Append("→");
  44. builder.Append(string.Format("【{0}】", currentItem.Text));
  45. builder.Append(string.Format(":{0}", currentItem.Id));
  46. builder.AppendLine();
  47. }
  48. }
  49. else
  50. {
  51. builder.Append(string.Format("【{0}】", currentTab.Title));
  52. builder.Append("→");
  53. builder.Append(string.Format("【{0}】", currentPanel.Source.Title));
  54. builder.Append("→");
  55. builder.Append(string.Format("【{0}】", item.Text));
  56. builder.Append(string.Format(":{0}", item.Id));
  57. builder.AppendLine();
  58. }
  59. }
  60. }
  61. }
  62. return builder;
  63. }
  64. #region 命令UI信息
  65. //可以实实在在的取到命令
  66. // var autoPlaceSpace=RevitCommandId.LookupCommandId("ID_SKETCH_PLANE_TOOL");
  67. // RevitCore.UIApp.PostCommand(RevitCommandId.LookupPostableCommandId(PostableCommand.Space));
  68. //ComponentManager.ItemExecuted += ComponentManager_ItemExecuted;
  69. //按名字去寻找命令ID
  70. // var autoPlaceSpace = RevitCommandId.LookupCommandId("Dialog_RoomAreaPlan_RoomTagDlgBar: Control_RoomAreaPlan_FindAllSpaces");
  71. // AddInCommandBinding binding = RevitCore.UIApp.CreateAddInCommandBinding(RevitCommandId.LookupPostableCommandId(PostableCommand.Space));
  72. #endregion
  73. public static void SetIsChecked(RibbonItem item, bool flag)
  74. {
  75. var useType = typeof(RibbonItem).Assembly.GetType("Autodesk.Internal.Windows.RibbonCommandItemBindings");
  76. MethodInfo mi = useType.GetMethod("TrySetIsChecked");
  77. if (mi != null)
  78. {
  79. mi?.Invoke(null, new object[] { item,flag });
  80. }
  81. }
  82. }
  83. }