/// <summary> /// Generate user interface. /// </summary> /// <param name="regenerateIfExists"> /// Indicates wheter to regenerate the user interface if it is already generated and loaded into Autocad. /// </param> public override void GenerateUi(bool regenerateIfExists) { if (!this.CheckAutoCadVersion(17, 0)) { Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(Resources.WarningUiVersion); return; } string kojtoCadCuiDir = DirectoriesAndFiles.KojtoCadTempDir; try { this.CreateUiFolderIfNotExists(kojtoCadCuiDir); } catch (IOException exception) { Logger.Error(Resources.ErrorCreatingUiDirectory, exception); Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(Resources.ErrorCreatingUiDirectory); } string kojtoCadCuiFile = kojtoCadCuiDir + "\\" + Settings.Default.appName + this.GetCuiExtensionForCurrentVersion(); if (this.GetMainCustomizationSection().PartialCuiFiles.Contains(kojtoCadCuiFile) && regenerateIfExists) { this.UnloadUiFromAutoCad(kojtoCadCuiFile); } else if (this.GetMainCustomizationSection().PartialCuiFiles.Contains(kojtoCadCuiFile) && !regenerateIfExists) { return; } if (File.Exists(kojtoCadCuiFile)) { File.Delete(kojtoCadCuiFile); } try { var kojtoCui = BuildMenu(MenuSchemaProvider.GetMenuSchemaFile(), this.GetCommandMethodsFromCurrentAssembly()); kojtoCui.SaveAs(kojtoCadCuiFile); } catch (System.Exception exception) { Logger.Error(Resources.ErrorCreatingUi, exception); Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(Resources.ErrorCreatingUi); } LoadUiIntoAutoCad(kojtoCadCuiFile); //this.LoadKojtoCAD3DUi(); //LoadKojtoCad3DUserInterface(); LoadKojtoCad3DUi(); //EditorHelper.WriteMessage(Resources.SuccessCreatingUi); }
private void PopulateToolbarItems() { var cuiFile = DirectoriesAndFiles.BcadCuiFile; var cuiFileName = new FileInfo(cuiFile).Name.Replace(new FileInfo(cuiFile).Extension, string.Empty); var app = Application.AcadApplication as AcadApplication; if (app == null) { MessageBox.Show("App was null!", "E R R O R", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var menuGroups = app.MenuGroups; var myGroup = menuGroups.GetMenuGroupByName(cuiFileName) ?? menuGroups.Load(cuiFile); var toolbars = myGroup.Toolbars; var commandMethods = GetCommandMethodsFromCurrentAssembly().Where(x => x.Value.Name.Length >= "Start".Length).ToArray(); var documentElement = MenuSchemaProvider.GetMenuSchemaFile().DocumentElement; if (documentElement != null) { var toolbarDefinitions = documentElement.ChildNodes; foreach (XmlNode toolBarDefinition in toolbarDefinitions) { if (toolBarDefinition.Attributes == null) { MessageBox.Show("XML file - toolbar name!", "E R R O R", MessageBoxButtons.OK, MessageBoxIcon.Error); continue; } var toolbarName = toolBarDefinition.Attributes["name"].Value; var toolbar = toolbars.GetToolbarByName(toolbarName); if (toolbar == null) { toolbar = toolbars.Add(toolbarName); toolbar.Dock(AcToolbarDockStatus.acToolbarDockRight); } foreach (XmlNode buttonDefinition in toolBarDefinition) { if (buttonDefinition.Attributes == null) { MessageBox.Show("XML file - method name!", "E R R O R", MessageBoxButtons.OK, MessageBoxIcon.Error); continue; } var buttonName = buttonDefinition.Attributes["methodName"].Value; var toolbarItem = toolbar.GetToolbarItemByName(buttonName); if (toolbarItem == null) { var buttonMethod = commandMethods.FirstOrDefault( x => x.Value.Name.Substring(0, x.Value.Name.Length - "Start".Length) .Equals(buttonName, StringComparison.InvariantCultureIgnoreCase)); toolbarItem = toolbar.AddToolbarButton(-1, buttonName, buttonDefinition.InnerText, buttonMethod.Key.GlobalName); var smallIcon = IconsManager.GetIconFile(buttonMethod.Value.Name.Replace("Start", ""), IconSize.Small); var largeIcon = IconsManager.GetIconFile(buttonMethod.Value.Name.Replace("Start", ""), IconSize.Large); if (!File.Exists(smallIcon) || !File.Exists(largeIcon)) { MessageBox.Show("Icon not found!", "E R R O R", MessageBoxButtons.OK, MessageBoxIcon.Error); continue; } toolbarItem.SetBitmaps(smallIcon, largeIcon); } } } } myGroup.Save(AcMenuFileType.acMenuFileSource); }