123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- /*-------------------------------------------------------------------------
- * 功能描述:SpaceMonitoringCommand
- * 作者:xulisong
- * 创建时间: 2019/3/19 11:15:57
- * 版本号:v1.0
- * -------------------------------------------------------------------------*/
- using FWindSoft.Revit;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using Autodesk.Revit.Attributes;
- using Autodesk.Revit.DB;
- using Autodesk.Revit.UI;
- using Autodesk.Windows;
- using LRH.Tool.RevitUI;
- using FWindSoft.Revit.Menu;
- using System.IO;
- using System.Diagnostics;
- namespace LRH.Tool
- {
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- [Button(ButtonName = "空间命令id获取")]
- public class SpaceMonitoringCommand: ExternalCommand
- {
- public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- var paneId = DockablePanes.BuiltInDockablePanes.PropertiesPalette;
- DockablePane pane = ExternalApplication.CurrentApp.UIControlApp.GetDockablePane(paneId);
- //ExternalApplication.CurrentApp.UIControlApp.cr
- MessageBox.Show(string.Format("Titile:{0},IsShow{1}", pane.GetTitle(), pane.IsShown()));
- var add = ComponentManager.Ribbon.FindItem("HID_APPLICATION_ELEMENTS_RibbonListButton", false) as RibbonListButton;
- //dd.dr
- var listButton = RevitCommandId.LookupCommandId("HID_APPLICATION_ELEMENTS_RibbonListButton");
-
- if (listButton != null)
- {
- RevitCore.UIApp.PostCommand(listButton);
- }
- var ribbonToggleButton = ComponentManager.Ribbon.FindItem("ID_TOGGLE_PROPERTIES_PALETTE", false, true) as RibbonToggleButton;
- if (ribbonToggleButton.IsChecked)
- {
- var propertyButton = RevitCommandId.LookupCommandId("ID_TOGGLE_PROPERTIES_PALETTE");
- if (propertyButton != null)
- {
- RevitCore.UIApp.PostCommand(propertyButton);
- }
- }
- var property = typeof(RibbonToggleButton).GetProperty("InternalIsChecked", BindingFlags.Instance | BindingFlags.NonPublic);
- if (ribbonToggleButton!=null&& property!=null)
- {
- //if ((bool?)property.GetValue(ribbonToggleButton) == true)
- if(true||ribbonToggleButton.IsChecked)
- {
- //如果界面不刷新,好像新修改的值不能同步
- //property.SetValue(ribbonToggleButton, false);
- //ribbonToggleButton.IsChecked = !ribbonToggleButton.IsChecked;
- //RevitUIUtils.SetIsChecked(ribbonToggleButton, ribbonToggleButton.IsChecked);
- //var methods = typeof(RibbonToggleButton).GetMethods( BindingFlags.Instance | BindingFlags.NonPublic);
- //foreach (var methodInfo in methods)
- //{
- // if (methodInfo.Name == "NotifyPropertyChanged")
- // {
- // var parameters = methodInfo.GetParameters();
- // if (parameters.Length == 1 && parameters[0].ParameterType == typeof(string))
- // {
- // methodInfo.Invoke(ribbonToggleButton, new object[] { RibbonToggleButton.IsCheckedPropertyName });
- // break;
- // }
- // }
- //}
- //var autoPlaceSpace = RevitCommandId.LookupCommandId("ID_TOGGLE_PROPERTIES_PALETTE");
- //if (autoPlaceSpace != null)
- //{
- // RevitCore.UIApp.PostCommand(autoPlaceSpace);
- //}
- }
- //ribbonToggleButton
- //ribbonToggleButton.IsChecked = false;
- }
- //var paneId = DockablePanes.BuiltInDockablePanes.PropertiesPalette;
- //DockablePane pane = ExternalApplication.CurrentApp.UIControlApp.GetDockablePane(paneId);
- //if(!string.IsNullOrWhiteSpace(pane.GetTitle()))
- //{
- // var command = RevitCommandId.LookupCommandId("ID_TOGGLE_PROPERTIES_PALETTE");
- // if (command != null)
- // {
- // RevitCore.UIApp.PostCommand(command);
- // }
- //}
- //var cc = pane.GetTitle();
- //return Result.Succeeded;
- //var autoPlaceSpace=RevitCommandId.LookupCommandId("ID_TOGGLE_PROPERTIES_PALETTE");
- //if (autoPlaceSpace != null)
- //{
- // RevitCore.UIApp.PostCommand(autoPlaceSpace);
- //}
- var stringBuilder = RevitUIUtils.CollectCommandIds();
- File.WriteAllText(@"D:\ccc.txt", stringBuilder.ToString());
- Process.Start("notepad.exe", @"D:\ccc.txt");
- return Result.Succeeded;
-
- }
- private void ComponentManager_ItemExecuted(object sender, Autodesk.Internal.Windows.RibbonItemExecutedEventArgs e)
- {
- if (PlaceSpaceCommand.PlaceCommand != null)
- {
- return;
- }
- var tempCommand = e.Item as RibbonCommandItem;
- tempCommand = ComponentManager.Ribbon.FindItem("ID_OBJECTS_WALL_RibbonListButton", false) as RibbonCommandItem;
- if (tempCommand == null)
- return;
- if (PlaceSpaceCommand.PlaceCommand == null)
- {
- PlaceSpaceCommand.PlaceCommand = new RevitUICommand(tempCommand);
- }
-
- //if (tempCommand.Id == "Dialog_RoomAreaPlan_RoomTagDlgBar: Control_RoomAreaPlan_FindAllSpaces")
- if (tempCommand.Text!=null&&tempCommand.Text.Contains("放置空间") && tempCommand.Text.Contains("自动"))
- {
- if (PlaceSpaceCommand.PlaceCommand == null)
- {
- PlaceSpaceCommand.PlaceCommand = new RevitUICommand(tempCommand);
- }
- }
- //RibbonTab tab = ComponentManager.Ribbon.ActiveTab;
- //foreach (var tabPanel in tab.Panels)
- //{
- // foreach (var ribbonItem in tabPanel.Source.GetItemEnumerator())
- // {
- // var tempCommand = ribbonItem as RibbonCommandItem;
- // if (tempCommand != null)
- // {
- // // tempCommand.Text.Contains("放置空间")
- // if (tempCommand.Id== "Dialog_RoomAreaPlan_RoomTagDlgBar: Control_RoomAreaPlan_FindAllSpaces")
- // {
- // if (PlaceSpaceCommand.PlaceCommand == null)
- // {
- // PlaceSpaceCommand.PlaceCommand = new RevitCommandSend(tempCommand);
- // }
- // }
- // }
- // }
- //}
- }
- }
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class PlaceSpaceCommand : ExternalCommand
- {
- public static RevitUICommand PlaceCommand;
- public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- if (PlaceCommand == null)
- {
- MessageBox.Show("放置空间命令未找到");
- return Result.Succeeded;
- }
- PlaceCommand.Execute();
- return Result.Succeeded;
- }
- }
-
- }
|