public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; doc.DocumentSaved -= new EventHandler <DocumentSavedEventArgs>(Helpers.OnDocumentSaved); app.DocumentSynchronizedWithCentral -= new EventHandler <DocumentSynchronizedWithCentralEventArgs>(Helpers.OnDocumentSynchronized); List <RibbonPanel> ribbons = uiapp.GetRibbonPanels(); foreach (RibbonPanel p in ribbons) { if (p.Name == "NWC View Exporter") { IList <RibbonItem> items = p.GetItems(); foreach (PushButton pb in items) { if (pb.Name == "Subscribe") { pb.Enabled = true; } if (pb.Name == "Unsubscribe") { pb.Enabled = false; } } } } return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Autodesk.Revit.ApplicationServices.Application app = uiapp.Application; Document doc = uidoc.Document; DockablePaneProviderData dpData = new DockablePaneProviderData(); DockPanel browser = new DockPanel(); dpData.FrameworkElement = browser as System.Windows.FrameworkElement; List <RibbonPanel> ribbon = uiapp.GetRibbonPanels(); foreach (var item in ribbon) { TaskDialog.Show("ribbon", item.ToString()); } //FilteredElementCollector col // = new FilteredElementCollector(doc) // .WhereElementIsNotElementType() // .OfCategory(BuiltInCategory.INVALID) // .OfClass(typeof(Wall)); return(Result.Succeeded); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; var panels = uiapp.GetRibbonPanels(CCRibbon.tabName); var box = panels.Where(x => x.Name == "Objects").First().GetItems().Where(x => x.Name == "Object Tools").First() as ComboBox; var current = box.Current.Name; switch (current) { default: case "Doors": Assembly assembly = Assembly.LoadFrom("C:\\ProgramData\\Autodesk\\Revit\\Addins\\2019\\CCPlugin\\Doors.dll"); uiapp.ActiveUIDocument.Document.UnpackFamilies(assembly); break; /* * case "Material Legend": * MaterialSchedule.Import(uiapp.ActiveUIDocument.Document, filepath); * break; */ } return(Result.Succeeded); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication app = commandData.Application; List <RibbonPanel> panels = app.GetRibbonPanels(); foreach (RibbonPanel panel in panels) { Debug.Print(panel.Name); IList <RibbonItem> items = panel.GetItems(); foreach (RibbonItem item in items) { RibbonItemType t = item.ItemType; if (RibbonItemType.PushButton == t) { PushButton b = item as PushButton; Debug.Print(" {0} : {1}", item.ItemText, b.Name); } else { Debug.Assert(RibbonItemType.PulldownButton == t, "expected pulldown button"); PulldownButton b = item as PulldownButton; Debug.Print(" {0} : {1}", item.ItemText, b.Name); foreach (RibbonItem item2 in b.GetItems()) { Debug.Assert(RibbonItemType.PushButton == item2.ItemType, "expected push button in pulldown menu"); Debug.Print(" {0} : {1}", item2.ItemText, ((PushButton)item2).Name); } } } } return(Result.Failed); }
/// <summary> /// 修改指定名称状态 /// </summary> /// <param name="app"></param> /// <param name="tabName"></param> /// <param name="panelNames"></param> /// <param name="b"></param> public static void SetPanels(UIApplication app, string tabName, string[] panelNames, bool b) { var panels = app.GetRibbonPanels(tabName); var ps = panels.Where(c => panelNames.Contains(c.Name)).ToArray(); foreach (var p in ps) { p.Enabled = b; } }
public static void SetItems(UIApplication app, string tabName, string panelNames, int[] itemIndices, bool b) { var panels = app.GetRibbonPanels(tabName); var ps = panels.Where(c => panelNames.Equals(c.Name)).ToArray(); foreach (var p in ps) { SetItems(p, itemIndices, b); } }
/// <summary> /// 修改指定位置状态 /// </summary> /// <param name="app"></param> /// <param name="tabName"></param> /// <param name="indices"></param> public static void SetPanels(UIApplication app, string tabName, int[] indices, bool b) { var panels = app.GetRibbonPanels(tabName); for (int i = 0; i < panels.Count; i++) { int index = Array.IndexOf(indices, i); if (index != -1) { panels[i].Enabled = b; } } }
private static void SetTB(UIApplication app, string val) { try { var panels = app.GetRibbonPanels(TabName); var panel = panels.Where(x => x.Name == PanelName).First(); var items = panel.GetItems(); var item = items.Where(x => x.ItemType == RibbonItemType.TextBox).First(); var tb = item as TextBox; tb.PromptText = val; tb.Value = string.Empty; } catch {} }
void ShowCommand(object s, IdlingEventArgs e) { UIApplication app = s as UIApplication; ICollection <ElementId> elementIds = app.ActiveUIDocument.Selection.GetElementIds(); List <PushButton> buttons = app.GetRibbonPanels("Walter")[0].GetItems().Where(w => w.Name == "Edit Element").Cast <PushButton>().ToList(); if (elementIds.Count == 1) { buttons[0].Enabled = true; } else { buttons[0].Enabled = false; } }
/// <summary> /// Restores the RibbonPanel. /// </summary> /// <param name="uiApp">The active UIApplication</param> /// <param name="args">null, needed for EventHandler.SetActionAndRaise()</param> private void RestoreModelessRibbonPanel(UIApplication uiApp, object args = null) { try { // Enable every individual ribbonPanel inside RIBBON_TAB_NAME // foreach (RibbonPanel ribbonPanel in uiApp.GetRibbonPanels(RIBBON_TAB_NAME)) foreach (RibbonPanel ribbonPanel in uiApp.GetRibbonPanels(Tab.AddIns)) { ribbonPanel.Enabled = true; } } catch (Exception ex) { ErrorReport.Report(ex); } }
private static string GetComboData(UIApplication app) { string val = ""; try { var panels = app.GetRibbonPanels(TabName); var panel = panels.Where(x => x.Name == PanelName).First(); var items = panel.GetItems(); var item = items.Where(x => x.ItemType == RibbonItemType.ComboBox).First(); var cb = item as ComboBox; val = cb.Current.Name; } catch (Exception e) { } return(val); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; RibbonPanel inputpanel = null; PushButton toggle_Insulation = null; foreach (RibbonPanel panel in uiapp.GetRibbonPanels("Exp. Add-Ins")) { if (panel.Name == "Re-Elevate") { inputpanel = panel; } } foreach (RibbonItem item in inputpanel.GetItems()) { if (item.Name == "Toggle_Insulation") { toggle_Insulation = (PushButton)item; } } string s = toggle_Insulation.ItemText; toggle_Insulation.ItemText = s.Equals("Align to INS") ? "Align to MEP" : "Align to INS"; //find and switch button and data string IconsPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "Icons\\"); string im_ins = IconsPath + "Button_Ins.png"; string im_nin = IconsPath + "Button_NoIns.png"; Uri uriImage = new Uri(im_nin); BitmapImage Image = new BitmapImage(uriImage); if (toggle_Insulation.ItemText == "Align to MEP") { uriImage = new Uri(im_nin); Image = new BitmapImage(uriImage); toggle_Insulation.Image = Image; } else { uriImage = new Uri(im_ins); Image = new BitmapImage(uriImage); toggle_Insulation.Image = Image; } return(Result.Succeeded); }
public static TI GetRibbonItem <TI>(this UIApplication uiApplication, string tabName, string panelName, string ribbonItemName) where TI : RibbonItem { RibbonPanel itemPanel = uiApplication.GetRibbonPanels(tabName).First(panel => panel.Name == panelName); if (itemPanel == null) { return(null); } var ritem = itemPanel.GetItems().First(item => item.Name == ribbonItemName); if (ritem == null) { return(null); } return((TI)ritem); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; var relayTab = RibbonUtils.GetTab("Relay"); //create the panels for the sub directories foreach (var directory in Directory.GetDirectories(Globals.RelayGraphs)) { //the upper folder name (panel name) DirectoryInfo dInfo = new DirectoryInfo(directory); Autodesk.Revit.UI.RibbonPanel panelToUse; //try to create the panel, if it already exists, just use it try { panelToUse = uiapp.CreateRibbonPanel("Relay", dInfo.Name); } catch (Exception) { panelToUse = uiapp.GetRibbonPanels("Relay").First(p => p.Name.Equals(dInfo.Name)); } //find the files that do not have a button yet var toCreate = Directory.GetFiles(directory, "*.dyn") .Where(f => RibbonUtils.GetButton("Relay", dInfo.Name, $"relay{new FileInfo(f).Name.Replace(" ", "")}") == null).ToArray(); //if the user is holding down the left shift key, then force the large icons bool forceLargeIcons = Keyboard.IsKeyDown(Key.LeftShift); RibbonUtils.AddItems(panelToUse, toCreate, forceLargeIcons); } //subscribe to the events of the button to associate the current DYN Autodesk.Windows.ComponentManager.UIElementActivated -= ComponentManagerOnUIElementActivated; Autodesk.Windows.ComponentManager.UIElementActivated += ComponentManagerOnUIElementActivated; return(Result.Succeeded); }
public static double[] GetComboData(UIApplication app) { double[] val = new double[2]; try { var panels = app.GetRibbonPanels(TabName); var panel = panels.Where(x => x.Name == PanelName).First(); var items = panel.GetItems(); var item1 = items.Where(x => x.ItemType == RibbonItemType.ComboBox).ElementAt(0); var item2 = items.Where(x => x.ItemType == RibbonItemType.ComboBox).ElementAt(1); var cb1 = item1 as ComboBox; var cb2 = item2 as ComboBox; val[0] = double.Parse(cb1.Current.Name.Split(' ').Last()); val[1] = double.Parse(cb2.Current.Name.Split(' ').Last()); } catch (Exception e) { } return(val); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; if (OptionalFunctionalityUtils.IsNavisworksExporterAvailable() == false) { TaskDialog.Show("Error", "No Compatible Navisworks plugins found. Please install a compatible Navisworks exporter to use with Revit."); return(Result.Failed); } else { doc.DocumentSaved += new EventHandler <DocumentSavedEventArgs>(Helpers.OnDocumentSaved); app.DocumentSynchronizedWithCentral += new EventHandler <DocumentSynchronizedWithCentralEventArgs>(Helpers.OnDocumentSynchronized); List <RibbonPanel> ribbons = uiapp.GetRibbonPanels(); foreach (RibbonPanel p in ribbons) { if (p.Name == "NWC View Exporter") { IList <RibbonItem> items = p.GetItems(); foreach (PushButton pb in items) { if (pb.Name == "Subscribe") { pb.Enabled = false; } if (pb.Name == "Unsubscribe") { pb.Enabled = true; } } } } return(Result.Succeeded); } }
public static PushButton GetButton(UIApplication uiapp, string panelname, string itemname) { RibbonPanel inputpanel = null; PushButton toggle_Insulation = null; foreach (RibbonPanel panel in uiapp.GetRibbonPanels("Exp. Add-Ins")) { if (panel.Name == panelname) { inputpanel = panel; } } foreach (RibbonItem item in inputpanel.GetItems()) { if (item.Name == itemname) { toggle_Insulation = (PushButton)item; } } return(toggle_Insulation); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; var panels = uiapp.GetRibbonPanels(CCRibbon.tabName); var box = panels.Where(x => x.Name == "Objects").First().GetItems().Where(x => x.Name == "Object Tools").First() as ComboBox; var current = box.Current.Name; switch (current) { default: case "Doors": DoorSchedule.CreateSched(uiapp.ActiveUIDocument.Document); break; case "Materials": MaterialSchedule.CreateSched(uiapp.ActiveUIDocument.Document); break; } return(Result.Succeeded); }
/// <summary> /// Insert Level into ComboBox - LevelsSelector /// </summary> /// <param name="evnetArgs">Autodesk.Revit.DB.Events.DocumentCreatedEventArgs</param> public void DocumentCreated(object sender, Autodesk.Revit.DB.Events.DocumentCreatedEventArgs e) { uiApplication = new UIApplication(e.Document.Application); List <RibbonPanel> myPanels = uiApplication.GetRibbonPanels(); Autodesk.Revit.UI.ComboBox comboboxLevel = (Autodesk.Revit.UI.ComboBox)(myPanels[0].GetItems()[2]); if (null == comboboxLevel) { return; } FilteredElementCollector collector = new FilteredElementCollector(uiApplication.ActiveUIDocument.Document); ICollection <Element> founds = collector.OfClass(typeof(Level)).ToElements(); foreach (Element elem in founds) { Level level = elem as Level; ComboBoxMemberData comboBoxMemberData = new ComboBoxMemberData(level.Name, level.Name); ComboBoxMember comboboxMember = comboboxLevel.AddItem(comboBoxMemberData); comboboxMember.Image = new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "LevelsSelector.png"), UriKind.Absolute)); } //refresh level list (in case user created new level after document created) comboboxLevel.DropDownOpened += new EventHandler <ComboBoxDropDownOpenedEventArgs>(AddNewLevels); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; var relayTab = RibbonUtils.GetTab("Relay"); //create the panels for the sub directories foreach (var directory in Directory.GetDirectories(Globals.RelayGraphs)) { DirectoryInfo dInfo = new DirectoryInfo(directory); Autodesk.Revit.UI.RibbonPanel panelToUse = null; try { panelToUse = uiapp.CreateRibbonPanel("Relay", dInfo.Name); } catch (Exception) { panelToUse = uiapp.GetRibbonPanels("Relay").First(p => p.Name.Equals(dInfo.Name)); } var toCreate = Directory.GetFiles(directory, "*.dyn") .Where(f => RibbonUtils.GetButton("Relay", dInfo.Name, $"relay{new FileInfo(f).Name.Replace(" ", "")}") == null).ToArray(); RibbonUtils.AddItems(panelToUse, toCreate); } //subscribe to the events of the button to associate the current DYN Autodesk.Windows.ComponentManager.UIElementActivated -= ComponentManagerOnUIElementActivated; Autodesk.Windows.ComponentManager.UIElementActivated += ComponentManagerOnUIElementActivated; return(Result.Succeeded); }
internal IEnumerable <RibbonPanel> GetRibbonPanels(string tabName) { return(ControlledApplication != null ? ControlledApplication.GetRibbonPanels(tabName) : uiApplication.GetRibbonPanels(tabName)); }
public static void GetMenuValues(UIApplication uiapp) { double scale = uiapp.ActiveUIDocument.ActiveView.Scale; Store.scaleMod = 96 / scale; RibbonPanel inputpanel = null; foreach (RibbonPanel panel in uiapp.GetRibbonPanels("Exp. Add-Ins")) { if (panel.Name == "Annotation") { inputpanel = panel; } } foreach (RibbonItem item in inputpanel.GetItems()) { if (item.Name == "A") { Store.left_ib = (TextBox)item; } else if (item.Name == "B") { Store.right_ib = (TextBox)item; } else if (item.Name == "C") { Store.firsty_ib = (TextBox)item; } else if (item.Name == "1") { Store.stepy_ib = (TextBox)item; } else if (item.Name == "2") { Store.split_ib = (TextBox)item; } else if (item.Name == "3") { Store.place_ib = (TextBox)item; } } Double.TryParse(Store.left_ib.Value as string, out Store.mod_left); Double.TryParse(Store.right_ib.Value as string, out Store.mod_right); Double.TryParse(Store.firsty_ib.Value as string, out Store.mod_firsty); Double.TryParse(Store.stepy_ib.Value as string, out Store.mod_stepy); int.TryParse(Store.split_ib.Value as string, out Store.mod_split); Double.TryParse(Store.place_ib.Value as string, out Store.mod_place); double mod = 1 / Store.scaleMod; if (Store.mod_left == 0) { Store.mod_left = mod; } else { Store.mod_left /= Store.scaleMod; } if (Store.mod_right == 0) { Store.mod_right = mod; } else { Store.mod_right /= Store.scaleMod; } if (Store.mod_firsty == 0) { Store.mod_firsty = mod; } else { Store.mod_firsty /= Store.scaleMod; } if (Store.mod_stepy == 0) { Store.mod_stepy = mod; } else { Store.mod_stepy /= Store.scaleMod; } }
public IEnumerable <Autodesk.Revit.UI.RibbonPanel> GetRibbonPanels(string tabName) { return(ControlledApplication != null ? ControlledApplication.GetRibbonPanels(tabName) : _uiapp.GetRibbonPanels(tabName)); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; if (!(doc.ActiveView is ViewPlan viewPlan)) { TaskDialog.Show("Please select Plan view", "Select Plan view to change it's View Range"); return(Result.Succeeded); } PlanViewRange viewRange = viewPlan.GetViewRange(); double CCut = viewRange.GetOffset(PlanViewPlane.CutPlane); double CTop = viewRange.GetOffset(PlanViewPlane.TopClipPlane); RibbonPanel inputpanel = null; ComboBox inputbox = null; foreach (RibbonPanel panel in uiapp.GetRibbonPanels("Exp. Add-Ins")) { if (panel.Name == "View Tools") { inputpanel = panel; } } foreach (RibbonItem item in inputpanel.GetItems()) { if (item.Name == "ShiftRange") { inputbox = (ComboBox)item; } } List <Double> vrOpts = new List <Double> { StoreExp.vrOpt1, StoreExp.vrOpt2, StoreExp.vrOpt3, StoreExp.vrOpt4, StoreExp.vrOpt5, StoreExp.vrOpt6 }; double mod = vrOpts[Int32.Parse(inputbox.Current.Name)]; if (viewPlan.ViewType != ViewType.CeilingPlan) { viewRange.SetOffset(PlanViewPlane.CutPlane, CCut + mod); viewRange.SetOffset(PlanViewPlane.TopClipPlane, CCut + mod); } if (viewPlan.ViewType == ViewType.CeilingPlan) { viewRange.SetOffset(PlanViewPlane.TopClipPlane, CTop + mod); viewRange.SetOffset(PlanViewPlane.ViewDepthPlane, CTop + mod); } using (Transaction t = new Transaction(doc, "Set View Range")) { try { t.Start(); viewPlan.SetViewRange(viewRange); t.Commit(); } catch { TaskDialog.Show("Error", "Cannot shift ViewRange this way."); } } return(Result.Succeeded); }
/// <summary> /// Insert Level into ComboBox - LevelsSelector /// </summary> /// <param name="evnetArgs">Autodesk.Revit.DB.Events.DocumentCreatedEventArgs</param> public void DocumentCreated(object sender, Autodesk.Revit.DB.Events.DocumentCreatedEventArgs e) { uiApplication = new UIApplication(e.Document.Application); List<RibbonPanel> myPanels = uiApplication.GetRibbonPanels(); Autodesk.Revit.UI.ComboBox comboboxLevel = (Autodesk.Revit.UI.ComboBox)(myPanels[0].GetItems()[2]); if (null == comboboxLevel) { return; } FilteredElementCollector collector = new FilteredElementCollector(uiApplication.ActiveUIDocument.Document); ICollection<Element> founds = collector.OfClass(typeof(Level)).ToElements(); foreach (Element elem in founds) { Level level = elem as Level; ComboBoxMemberData comboBoxMemberData = new ComboBoxMemberData(level.Name, level.Name); ComboBoxMember comboboxMember = comboboxLevel.AddItem(comboBoxMemberData); comboboxMember.Image = new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "LevelsSelector.png"), UriKind.Absolute)); } //refresh level list (in case user created new level after document created) comboboxLevel.DropDownOpened += new EventHandler<ComboBoxDropDownOpenedEventArgs>(AddNewLevels); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { //Excel名称及路径 //string fileName = "pipeCalc"; //string filePath = @"C:\Users\Administrator\Desktop\test\" + fileName + ".xlsx"; string fullName = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + @"\test\PlumbingCalc.xlsx"; //Sheet1名称 string sheet1Name = "给排水工程量"; //第一个单元格 int startCol = 2; int startRow = 2; //获得按钮组 UIApplication uiapp = commandData.Application; foreach (var ribbonPanel in uiapp.GetRibbonPanels("Test")) { if (ribbonPanel.Name == "Excel Tool") { foreach (var item in ribbonPanel.GetItems()) { var rbg = item as RadioButtonGroup; if (rbg != null && rbg.Name == "Link_test") { //实例化更新器 Updater.PipeParameterUpdater ppu = new Updater.PipeParameterUpdater(commandData.Application.ActiveAddInId, fullName, sheet1Name); //更新器ID UpdaterId updaterId = ppu.GetUpdaterId(); if (UpdaterRegistry.IsUpdaterRegistered(updaterId)) { if (UpdaterRegistry.IsUpdaterEnabled(updaterId)) { UpdaterRegistry.DisableUpdater(updaterId); //切换按钮 foreach (ToggleButton tog in rbg.GetItems()) { if (tog.Name == "link_disable") { rbg.Current = tog; } } } else { Tool.ExcelTool excelTool = new Tool.ExcelTool(); excelTool.UpdataInOpenWorkBook(commandData.Application.ActiveUIDocument.Document, fullName, sheet1Name, startRow, startCol); UpdaterRegistry.EnableUpdater(updaterId); } } else { message = "未能启动更新器,请联系XXX"; return(Result.Failed); } break; } } break; } } return(Result.Succeeded); }