1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- using Autodesk.Windows;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- namespace LRH.Tool.RevitUI
- {
- /// <summary>
- /// RevitUI操作相关
- /// </summary>
- public class RevitUIUtils
- {
- /// <summary>
- /// 收集CommandIds
- /// </summary>
- /// <returns></returns>
- public static StringBuilder CollectCommandIds()
- {
- RibbonControl control = ComponentManager.Ribbon;
- StringBuilder builder = new StringBuilder();
- foreach (var currentTab in control.Tabs)
- {
-
-
- foreach (var currentPanel in currentTab.Panels)
- {
-
- foreach (var item in currentPanel.Source.Items)
- {
- //if(!(item is RibbonCommandItem||item is RibbonCheckBox))
- //{
- // continue;
- //}
- if(item is RibbonListButton listButton)
- {
- foreach (var currentItem in listButton.Items)
- {
- if (currentItem.Id == "ID_TOGGLE_PROPERTIES_PALETTE")
- {
- }
- builder.Append(string.Format("【{0}】", currentTab.Title));
- builder.Append("→");
- builder.Append(string.Format("【{0}】", currentPanel.Source.Title));
- builder.Append("→");
- builder.Append(string.Format("【{0}】", currentItem.Text));
- builder.Append(string.Format(":{0}", currentItem.Id));
- builder.AppendLine();
- }
- }
- else
- {
- builder.Append(string.Format("【{0}】", currentTab.Title));
- builder.Append("→");
- builder.Append(string.Format("【{0}】", currentPanel.Source.Title));
- builder.Append("→");
- builder.Append(string.Format("【{0}】", item.Text));
- builder.Append(string.Format(":{0}", item.Id));
- builder.AppendLine();
- }
-
- }
- }
- }
- return builder;
- }
- #region 命令UI信息
- //可以实实在在的取到命令
- // var autoPlaceSpace=RevitCommandId.LookupCommandId("ID_SKETCH_PLANE_TOOL");
- // RevitCore.UIApp.PostCommand(RevitCommandId.LookupPostableCommandId(PostableCommand.Space));
- //ComponentManager.ItemExecuted += ComponentManager_ItemExecuted;
- //按名字去寻找命令ID
- // var autoPlaceSpace = RevitCommandId.LookupCommandId("Dialog_RoomAreaPlan_RoomTagDlgBar: Control_RoomAreaPlan_FindAllSpaces");
- // AddInCommandBinding binding = RevitCore.UIApp.CreateAddInCommandBinding(RevitCommandId.LookupPostableCommandId(PostableCommand.Space));
- #endregion
- public static void SetIsChecked(RibbonItem item, bool flag)
- {
- var useType = typeof(RibbonItem).Assembly.GetType("Autodesk.Internal.Windows.RibbonCommandItemBindings");
- MethodInfo mi = useType.GetMethod("TrySetIsChecked");
- if (mi != null)
- {
- mi?.Invoke(null, new object[] { item,flag });
- }
- }
- }
- }
|