public override int Execute(params string[] parameters) { //load the application if (!NavisPythonShellApplication.applicationLoaded) { NavisPythonShellApplication.OnLoaded(); } var dialog = new ConfigureCommandsForm(); dialog.ShowDialog(); //MessageBox.Show("Restart Navisworks to see changes to the commands in the Ribbon", "Configure NavisPythonShell", MessageBoxButtons.OK, MessageBoxIcon.Information); return(0); }
/// <summary> /// Overload this method to implement an external command within Revit. /// </summary> /// <returns> /// The result indicates if the execution fails, succeeds, or was canceled by user. If it does not /// succeed, Revit will undo any changes made by the external command. /// </returns> int Execute(ref string message, params string[] parameters) { // FIXME: somehow fetch back message after script execution... var executor = new ScriptExecutor(NavisPythonShellApplication.GetConfig()); string source; using (var reader = File.OpenText(_scriptSource)) { source = reader.ReadToEnd(); } var result = executor.ExecuteScript(source, _scriptSource); message = executor.Message; return(result); }
/// <summary> /// Read in the commands from the XML file and display them in the /// list. /// </summary> private void ConfigureCommandsForm_Load(object sender, EventArgs e) { _commands = NavisPythonShellApplication.GetCommands( NavisPythonShellApplication.GetSettings()).ToList(); lstCommands.DataSource = _commands; _searchPaths = NavisPythonShellApplication.GetConfig().GetSearchPaths().ToList(); lstSearchPaths.DataSource = _searchPaths; _variables = NavisPythonShellApplication.GetConfig().GetVariables().AsEnumerable().ToList(); lstVariables.DataSource = _variables; lstVariables.DisplayMember = "Key"; string initScriptPath = NavisPythonShellApplication.GetInitScriptPath(); txtInitScript.Text = initScriptPath; string startupScriptPath = NavisPythonShellApplication.GetStartupScriptPath(); txtStartupScript.Text = startupScriptPath; }
/// <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 (!NavisPythonShellApplication.applicationLoaded) { NavisPythonShellApplication.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(NavisPythonShellApplication.GetConfig()) .SetupEnvironment(host.Engine, host.Console.ScriptScope); host.Console.ScriptScope.SetVariable("__window__", gui); // run the initscript var initScript = NavisPythonShellApplication.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); }
/// <summary> /// Save changes to NavisPythonShell.xml and close Dialog. /// </summary> private void btnCommandSave_Click(object sender, EventArgs e) { NavisPythonShellApplication.WriteSettings(_commands, _searchPaths, _variables, txtInitScript.Text, txtStartupScript.Text); Close(); }