Revit二次开发,将插件按钮(Ribbon)变灰或者隐藏
http://www.cnblogs.com/greatverve/archive/2012/03/30/revit-api-get-ribbon.html 博主:大气象
http://www.cnblogs.com/chendongbky/p/6274690.html 博主: 苏州城外的微笑
转载自以上两篇博客
//得到Ribbon控件的值 [TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)] public class cmdTest : IExternalCommand { public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements) { UIApplication uiApp = commandData.Application; Document doc = uiApp.ActiveUIDocument.Document; Selection sel = uiApp.ActiveUIDocument.Selection; Transaction ts = new Transaction(doc, "http://revit.5d6d.com"); ts.Start(); RibbonPanel ribbonPanel = null; List<RibbonPanel> listPanel = commandData.Application.GetRibbonPanels("Tab名称"); foreach (RibbonPanel panel in listPanel) { if (panel.Name == "RibbonPanel名称")//RibbonPanel的Name { ribbonPanel = panel; break; } } IList<RibbonItem> listItem = ribbonPanel.GetItems(); foreach (RibbonItem item in listItem) { if (item.Name == "Ribbon名字")//Ribbon的Name属性 { item.Enabled = false;//false即为按钮变灰 }
} ts.Commit(); return Result.Succeeded; } }
如果是对按钮进行动态隐藏,只需将Enabled属性换成Visible就可以了。