SpaceMonitoringCommand.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:SpaceMonitoringCommand
  3. * 作者:xulisong
  4. * 创建时间: 2019/3/19 11:15:57
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using FWindSoft.Revit;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Reflection;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows;
  15. using Autodesk.Revit.Attributes;
  16. using Autodesk.Revit.DB;
  17. using Autodesk.Revit.UI;
  18. using Autodesk.Windows;
  19. using LRH.Tool.RevitUI;
  20. using FWindSoft.Revit.Menu;
  21. using System.IO;
  22. using System.Diagnostics;
  23. namespace LRH.Tool
  24. {
  25. [Transaction(TransactionMode.Manual)]
  26. [Regeneration(RegenerationOption.Manual)]
  27. [Button(ButtonName = "空间命令id获取")]
  28. public class SpaceMonitoringCommand: ExternalCommand
  29. {
  30. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  31. {
  32. var paneId = DockablePanes.BuiltInDockablePanes.PropertiesPalette;
  33. DockablePane pane = ExternalApplication.CurrentApp.UIControlApp.GetDockablePane(paneId);
  34. //ExternalApplication.CurrentApp.UIControlApp.cr
  35. MessageBox.Show(string.Format("Titile:{0},IsShow{1}", pane.GetTitle(), pane.IsShown()));
  36. var add = ComponentManager.Ribbon.FindItem("HID_APPLICATION_ELEMENTS_RibbonListButton", false) as RibbonListButton;
  37. //dd.dr
  38. var listButton = RevitCommandId.LookupCommandId("HID_APPLICATION_ELEMENTS_RibbonListButton");
  39. if (listButton != null)
  40. {
  41. RevitCore.UIApp.PostCommand(listButton);
  42. }
  43. var ribbonToggleButton = ComponentManager.Ribbon.FindItem("ID_TOGGLE_PROPERTIES_PALETTE", false, true) as RibbonToggleButton;
  44. if (ribbonToggleButton.IsChecked)
  45. {
  46. var propertyButton = RevitCommandId.LookupCommandId("ID_TOGGLE_PROPERTIES_PALETTE");
  47. if (propertyButton != null)
  48. {
  49. RevitCore.UIApp.PostCommand(propertyButton);
  50. }
  51. }
  52. var property = typeof(RibbonToggleButton).GetProperty("InternalIsChecked", BindingFlags.Instance | BindingFlags.NonPublic);
  53. if (ribbonToggleButton!=null&& property!=null)
  54. {
  55. //if ((bool?)property.GetValue(ribbonToggleButton) == true)
  56. if(true||ribbonToggleButton.IsChecked)
  57. {
  58. //如果界面不刷新,好像新修改的值不能同步
  59. //property.SetValue(ribbonToggleButton, false);
  60. //ribbonToggleButton.IsChecked = !ribbonToggleButton.IsChecked;
  61. //RevitUIUtils.SetIsChecked(ribbonToggleButton, ribbonToggleButton.IsChecked);
  62. //var methods = typeof(RibbonToggleButton).GetMethods( BindingFlags.Instance | BindingFlags.NonPublic);
  63. //foreach (var methodInfo in methods)
  64. //{
  65. // if (methodInfo.Name == "NotifyPropertyChanged")
  66. // {
  67. // var parameters = methodInfo.GetParameters();
  68. // if (parameters.Length == 1 && parameters[0].ParameterType == typeof(string))
  69. // {
  70. // methodInfo.Invoke(ribbonToggleButton, new object[] { RibbonToggleButton.IsCheckedPropertyName });
  71. // break;
  72. // }
  73. // }
  74. //}
  75. //var autoPlaceSpace = RevitCommandId.LookupCommandId("ID_TOGGLE_PROPERTIES_PALETTE");
  76. //if (autoPlaceSpace != null)
  77. //{
  78. // RevitCore.UIApp.PostCommand(autoPlaceSpace);
  79. //}
  80. }
  81. //ribbonToggleButton
  82. //ribbonToggleButton.IsChecked = false;
  83. }
  84. //var paneId = DockablePanes.BuiltInDockablePanes.PropertiesPalette;
  85. //DockablePane pane = ExternalApplication.CurrentApp.UIControlApp.GetDockablePane(paneId);
  86. //if(!string.IsNullOrWhiteSpace(pane.GetTitle()))
  87. //{
  88. // var command = RevitCommandId.LookupCommandId("ID_TOGGLE_PROPERTIES_PALETTE");
  89. // if (command != null)
  90. // {
  91. // RevitCore.UIApp.PostCommand(command);
  92. // }
  93. //}
  94. //var cc = pane.GetTitle();
  95. //return Result.Succeeded;
  96. //var autoPlaceSpace=RevitCommandId.LookupCommandId("ID_TOGGLE_PROPERTIES_PALETTE");
  97. //if (autoPlaceSpace != null)
  98. //{
  99. // RevitCore.UIApp.PostCommand(autoPlaceSpace);
  100. //}
  101. var stringBuilder = RevitUIUtils.CollectCommandIds();
  102. File.WriteAllText(@"D:\ccc.txt", stringBuilder.ToString());
  103. Process.Start("notepad.exe", @"D:\ccc.txt");
  104. return Result.Succeeded;
  105. }
  106. private void ComponentManager_ItemExecuted(object sender, Autodesk.Internal.Windows.RibbonItemExecutedEventArgs e)
  107. {
  108. if (PlaceSpaceCommand.PlaceCommand != null)
  109. {
  110. return;
  111. }
  112. var tempCommand = e.Item as RibbonCommandItem;
  113. tempCommand = ComponentManager.Ribbon.FindItem("ID_OBJECTS_WALL_RibbonListButton", false) as RibbonCommandItem;
  114. if (tempCommand == null)
  115. return;
  116. if (PlaceSpaceCommand.PlaceCommand == null)
  117. {
  118. PlaceSpaceCommand.PlaceCommand = new RevitUICommand(tempCommand);
  119. }
  120. //if (tempCommand.Id == "Dialog_RoomAreaPlan_RoomTagDlgBar: Control_RoomAreaPlan_FindAllSpaces")
  121. if (tempCommand.Text!=null&&tempCommand.Text.Contains("放置空间") && tempCommand.Text.Contains("自动"))
  122. {
  123. if (PlaceSpaceCommand.PlaceCommand == null)
  124. {
  125. PlaceSpaceCommand.PlaceCommand = new RevitUICommand(tempCommand);
  126. }
  127. }
  128. //RibbonTab tab = ComponentManager.Ribbon.ActiveTab;
  129. //foreach (var tabPanel in tab.Panels)
  130. //{
  131. // foreach (var ribbonItem in tabPanel.Source.GetItemEnumerator())
  132. // {
  133. // var tempCommand = ribbonItem as RibbonCommandItem;
  134. // if (tempCommand != null)
  135. // {
  136. // // tempCommand.Text.Contains("放置空间")
  137. // if (tempCommand.Id== "Dialog_RoomAreaPlan_RoomTagDlgBar: Control_RoomAreaPlan_FindAllSpaces")
  138. // {
  139. // if (PlaceSpaceCommand.PlaceCommand == null)
  140. // {
  141. // PlaceSpaceCommand.PlaceCommand = new RevitCommandSend(tempCommand);
  142. // }
  143. // }
  144. // }
  145. // }
  146. //}
  147. }
  148. }
  149. [Transaction(TransactionMode.Manual)]
  150. [Regeneration(RegenerationOption.Manual)]
  151. public class PlaceSpaceCommand : ExternalCommand
  152. {
  153. public static RevitUICommand PlaceCommand;
  154. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  155. {
  156. if (PlaceCommand == null)
  157. {
  158. MessageBox.Show("放置空间命令未找到");
  159. return Result.Succeeded;
  160. }
  161. PlaceCommand.Execute();
  162. return Result.Succeeded;
  163. }
  164. }
  165. }