public static void LoadToolbars(string cuiName, string cuixFile) { var app = Application.AcadApplication as AcadApplication; AcadMenuGroups mgroups = app.MenuGroups; var ed = Application.DocumentManager.MdiActiveDocument.Editor; var mg = default(AcadMenuGroup); try { //Attempt to access our menugroup mg = mgroups.Item(cuiName); } catch (System.Exception) { try { ; //Failure simply means we need to load the CUI first mgroups.Load(cuixFile); mg = mgroups.Item(cuiName); } catch (Exception) { throw new InvalidOperationException("指定的局部自定义文件中没有对应的名称!"); } } foreach (AcadMenuGroup g in mgroups) { ed.WriteMessage("\n" + g.MenuFileName + ",\t" + g.Name); } //Cycle through the toobars, setting them to visible ed.WriteMessage("\n" + mg.Toolbars.Count.ToString()); ed.WriteMessage("\n" + mg.Menus.Count.ToString()); for (int i = 0; i <= mg.Toolbars.Count - 1; i++) { ed.WriteMessage("\n" + mg.Toolbars.Item(i).Name.ToString() + "\n"); mg.Toolbars.Item(i).Visible = true; } }
public static AcadMenuGroup GetMenuGroupByName(this AcadMenuGroups menuGroups, string name) { for (var i = 0; i < menuGroups.Count; i++) { var g = menuGroups.Item(i); if (!g.Name.Equals(name, StringComparison.OrdinalIgnoreCase)) { continue; } return(g); } return(null); }