public Result OnStartup(UIControlledApplication application) { try { string appPath = Path.GetDirectoryName(typeof(LinkApp).Assembly.Location); string buttonLibPath = Path.Combine(appPath, "Elk.Buttons.dll"); string configPath = Path.Combine(appPath, "Elk.Buttons.config"); // If the config path is valid, regenerate the buttons if (File.Exists(configPath)) { try { LinkCommon.GetPanels(configPath, out List <PanelInfo> panels, out List <CommandInfo> commands); if (null != panels && panels.Count > 0) { LinkCommon.CompileButtons(panels); // Try to replace the buttons file... if (File.Exists(buttonLibPath) && File.Exists(Path.Combine(appPath, "Elk.Buttons_new.dll"))) { File.Delete(buttonLibPath); File.Move(Path.Combine(appPath, "Elk.Buttons_new.dll"), buttonLibPath); } } } catch (Exception ex) { TaskDialog dlg = new TaskDialog("Error"); dlg.TitleAutoPrefix = false; dlg.MainInstruction = "Error Compiling New Link Buttons"; dlg.MainContent = ex.Message; } } if (File.Exists(buttonLibPath)) { List <PanelInfo> panels = new List <PanelInfo>(); LinkCommon.GetPanels(buttonLibPath, out panels); //intantiate the buttons LinkCommon.InstantiateButtons(application, panels, buttonLibPath, appPath); } return(Result.Succeeded); } catch (Exception ex) { TaskDialog.Show("Error", ex.Message); return(Result.Failed); } }
private void okButton_Click(object sender, RoutedEventArgs e) { try { bool compiled = LinkCommon.CompileButtons(panels.ToList()); Close(); if (compiled) { MessageBox.Show("NOTE:\nChanges to the Links will appear after restarting Revit."); } else { MessageBox.Show("Was not able to create new buttons."); } } catch (Exception ex) { MessageBox.Show("Error\n" + ex.ToString()); } }