通过获取Revit按钮ID的方式通过反射调用Revit按钮未公开的函数:
public class CmdInvoke : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
//commandData.Application.ActiveUIDocument.Document;
// 调用Look up Snoop Db
// Look up Snoop Db 命令Id通过下方执行下方命令CmdInvokeTest,控制台输出查询。
//InvokeHelper.Invoke("CustomCtrl_%CustomCtrl_%CustomCtrl_%Add-Ins%Revit Lookup%Options%Snoop Db..");
/* 调用右键菜单 - 区域放大
右键菜单的 命令Id 可在Revit日志内进行查询..*/
InvokeHelper.Invoke("ID_FILE_SAVE_TO_MASTER_SHORTCUT");
return Result.Succeeded;
}
}
[Transaction(TransactionMode.Manual)]
public class CmdInvokeTest : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
// 当命令控件点击执行后触发事件...
ComponentManager.ItemExecuted -= ComponentManager_ItemExecuted;
return Result.Succeeded;
}
void ComponentManager_ItemExecuted(object sender, Autodesk.Internal.Windows.RibbonItemExecutedEventArgs e)
{
if (e.Item == null)
return;
// 获取命令Id
//var id = UIFramework.ControlHelper.GetCommandId(e.Item);
Autodesk.Revit.UI.TaskDialog.Show("tip", e.Item.Id);
}
}
public static class InvokeHelper
{
/// <summary>
/// 指定一个命令Id,调用命令.
/// </summary>
/// <param name="id">命令控件的Id值</param>
/// <returns></returns>
public static bool Invoke(string cmdId)
{
if (ExternalCommandHelper.CanExecute(cmdId))
{
ExternalCommandHelper.executeExternalCommand(cmdId);
return true;
}
else if (CommandHandlerService.canExecute(cmdId))
{
CommandHandlerService.invokeCommandHandler(cmdId);
return true;
}
else
{
return false;
}
}
}