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);
            }
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            try
            {
                appPath   = new FileInfo(typeof(ManageLinkApp).Assembly.Location).DirectoryName;
                directory = appPath;
                string buttonLibPath = directory + "\\Elk.Buttons.dll";

                List <PanelInfo> panels = new List <PanelInfo>();

                if (File.Exists(buttonLibPath))
                {
                    LinkCommon.GetPanels(buttonLibPath, out panels);
                }

                // Get the version
                int version = Convert.ToInt32(commandData.Application.Application.VersionNumber);

                // Get the Revit window handle
                IntPtr handle = IntPtr.Zero;
                if (version < 2019)
                {
                    handle = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
                }
                else
                {
                    handle = commandData.Application.GetType().GetProperty("MainWindowHandle") != null
                        ? (IntPtr)commandData.Application.GetType().GetProperty("MainWindowHandle").GetValue(commandData.Application)
                        : IntPtr.Zero;
                }
                ManageLinksForm form = new ManageLinksForm(buttonLibPath, panels);
                System.Windows.Interop.WindowInteropHelper helper = new System.Windows.Interop.WindowInteropHelper(form);
                helper.Owner = handle;
                form.Show();
                return(Result.Succeeded);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(Result.Failed);
            }
        }
Пример #3
0
        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());
            }
        }