Ejemplo n.º 1
0
        public Autodesk.Revit.UI.Result Execute(
            Autodesk.Revit.UI.ExternalCommandData commandData,
            ref string message, Autodesk.Revit.DB.ElementSet elementSet)
        {
            UIApplication uiApp = new UIApplication(commandData.Application.Application);

            bool error = false;

            try
            {
                // if the browser window/process is already open, activate it instead of opening a new process
                if (MessageHandler.library_pid != 0)
                {
                    // the following line could be enough, but rather activate the window thru the process
                    //SetForegroundWindow(MessageHandler.browser_hwnd);

                    // try to activate the existing instance
                    Process[] processes = Process.GetProcesses();

                    foreach (Process p in processes)
                    {
                        if (p.Id == MessageHandler.library_pid)
                        {
                            IntPtr windowHandle = p.MainWindowHandle;
                            SetForegroundWindow(windowHandle);
                            return(Result.Succeeded);
                        }
                    }
                }

                // execute the library window process
                Process process = new Process();
                process.StartInfo.FileName  = AssemblyDirectory + "\\Part_Library_App.exe ";
                process.StartInfo.Arguments = App.messagehandler.Handle.ToString(); // pass the MessageHandler's window handle the the process as a command line argument
                process.Start();

                MessageHandler.library_pid = process.Id; // grab the PID so we can kill the process if required;

                ExternalEventPL.RunExternal();

                return(Result.Succeeded);
            }
            catch (Exception e)
            {
                // if revit threw an exception, try to catch it
                TaskDialog.Show("Error", e.Message);
                error = true;
                return(Autodesk.Revit.UI.Result.Failed);
            }
            finally
            {
                // if revit threw an exception, display error and return failed
                if (error)
                {
                    TaskDialog.Show("Error", "Part Library failed.");
                }
            }
        }
Ejemplo n.º 2
0
        public static void RunExternal()
        {
            // A new handler to handle request posting by the dialog
            m_ExHandler = new ExternalEventPL();

            // External Event for the dialog to use (to post requests)
            m_ExEvent = ExternalEvent.Create(m_ExHandler);

            Thread _thread = new Thread(CheckForChanges);

            _thread.Start();

            return;
        }