GetInitScript() 공개 정적인 메소드

Returns a string to be executed, whenever the interactive shell is started. If this is not specified in the XML file (under /RevitPythonShell/InitScript), then null is returned.
public static GetInitScript ( ) : string
리턴 string
예제 #1
0
        /// <summary>
        /// Open a window to let the user enter python code.
        /// </summary>
        /// <returns></returns>
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            var messageCopy = message;
            var gui         = new IronPythonConsole();

            gui.consoleControl.WithConsoleHost((host) =>
            {
                // now that the console is created and initialized, the script scope should
                // be accessible...
                new ScriptExecutor(RevitPythonShellApplication.GetConfig(), commandData, messageCopy, elements)
                .SetupEnvironment(host.Engine, host.Console.ScriptScope);

                host.Console.ScriptScope.SetVariable("__window__", gui);

                // run the initscript
                var initScript = RevitPythonShellApplication.GetInitScript();
                if (initScript != null)
                {
                    var scriptSource = host.Engine.CreateScriptSourceFromString(initScript, SourceCodeKind.Statements);
                    scriptSource.Execute(host.Console.ScriptScope);
                }
            });

            var dispatcher = Dispatcher.FromThread(Thread.CurrentThread);

            gui.consoleControl.WithConsoleHost((host) =>
            {
                host.Console.SetCommandDispatcher((command) =>
                {
                    if (command != null)
                    {
                        // Slightly involved form to enable keyboard interrupt to work.
                        var executing = true;
                        var operation = dispatcher.BeginInvoke(DispatcherPriority.Normal, command);
                        while (executing)
                        {
                            if (operation.Status != DispatcherOperationStatus.Completed)
                            {
                                operation.Wait(TimeSpan.FromSeconds(1));
                            }
                            if (operation.Status == DispatcherOperationStatus.Completed)
                            {
                                executing = false;
                            }
                        }
                    }
                });
            });
            gui.ShowDialog();
            return(Result.Succeeded);
        }
        /// <summary>
        /// Open a window to let the user enter python code.
        /// </summary>
        /// <returns></returns>
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            var messageCopy = message;
            var gui         = new IronPythonConsole();

            gui.consoleControl.WithConsoleHost((host) =>
            {
                // now that the console is created and initialized, the script scope should
                // be accessible...
                new ScriptExecutor(RevitPythonShellApplication.GetConfig(), commandData, messageCopy, elements)
                .SetupEnvironment(host.Engine, host.Console.ScriptScope);

                host.Console.ScriptScope.SetVariable("__window__", gui);

                // run the initscript
                var initScript = RevitPythonShellApplication.GetInitScript();
                if (initScript != null)
                {
                    var scriptSource = host.Engine.CreateScriptSourceFromString(initScript, SourceCodeKind.Statements);
                    scriptSource.Execute(host.Console.ScriptScope);
                }
            });
            var commandCompletedEvent = new AutoResetEvent(false);
            var externalEventHandler  = new IronPythonExternalEventDispatcher(gui, commandCompletedEvent);
            var externalEvent         = ExternalEvent.Create(externalEventHandler);

            gui.consoleControl.WithConsoleHost((host) =>
            {
                var oldDispatcher = host.Console.GetCommandDispatcher();
                host.Console.SetCommandDispatcher((command) =>
                {
                    //externalEventHandler.Enqueue(() => oldDispatcher(command));
                    externalEventHandler.Enqueue(command);
                    externalEvent.Raise();
                    commandCompletedEvent.WaitOne();
                });

                host.Editor.SetCompletionDispatcher((command) =>
                {
                    externalEventHandler.Enqueue(command);
                    externalEvent.Raise();
                    commandCompletedEvent.WaitOne();
                });
            });
            gui.Topmost = true;
            gui.Title   = "RevitPythonShell (non-modal)";
            gui.Show();
            return(Result.Succeeded);
        }
예제 #3
0
        /// <summary>
        /// Open a window to let the user enter python code.
        /// </summary>
        /// <returns></returns>
        public override int Execute(params string[] parameters)
        {
            //load the application
            if (!RevitPythonShellApplication.applicationLoaded)
            {
                RevitPythonShellApplication.OnLoaded();
            }

            var gui = new IronPythonConsole();

            gui.consoleControl.WithConsoleHost((host) =>
            {
                // now that the console is created and initialized, the script scope should
                // be accessible...
                new ScriptExecutor(RevitPythonShellApplication.GetConfig())
                .SetupEnvironment(host.Engine, host.Console.ScriptScope);

                host.Console.ScriptScope.SetVariable("__window__", gui);

                // run the initscript
                var initScript = RevitPythonShellApplication.GetInitScript();
                if (initScript != null)
                {
                    try
                    {
                        var scriptSource = host.Engine.CreateScriptSourceFromString(initScript, SourceCodeKind.Statements);
                        scriptSource.Execute(host.Console.ScriptScope);
                    }
                    catch (Exception ex)
                    {
                        Forms.MessageBox.Show(ex.ToString(), "Something went horribly wrong!");
                    }
                }
            });

            var dispatcher = Dispatcher.FromThread(Thread.CurrentThread);

            gui.consoleControl.WithConsoleHost((host) =>
            {
                host.Console.SetCommandDispatcher((command) =>
                {
                    if (command != null)
                    {
                        // Slightly involved form to enable keyboard interrupt to work.
                        var executing = true;
                        var operation = dispatcher.BeginInvoke(DispatcherPriority.Normal, command);
                        while (executing)
                        {
                            if (operation.Status != DispatcherOperationStatus.Completed)
                            {
                                operation.Wait(TimeSpan.FromSeconds(1));
                            }
                            if (operation.Status == DispatcherOperationStatus.Completed)
                            {
                                executing = false;
                            }
                        }
                    }
                });
                host.Editor.SetCompletionDispatcher((command) =>
                {
                    var executing = true;
                    var operation = dispatcher.BeginInvoke(DispatcherPriority.Normal, command);
                    while (executing)
                    {
                        if (operation.Status != DispatcherOperationStatus.Completed)
                        {
                            operation.Wait(TimeSpan.FromSeconds(1));
                        }
                        if (operation.Status == DispatcherOperationStatus.Completed)
                        {
                            executing = false;
                        }
                    }
                });
            });
            gui.ShowDialog();
            return(0);
        }