Пример #1
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        ///

        protected override void SolveInstance(IGH_DataAccess DA)
        {
            PythonIDE.Text = this.NickName;
            retrievedData  = PythonIDE.PythonCanvas.Text;
            string output = "";

            try
            {
                if (Globals.OpenThisShell[thisIndex] == true)
                {
                    PythonIDE.Show();
                }
                else
                {
                    PythonIDE.Hide();
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.ToString());
            }
            writeReadPythonFile(this);
            System.IO.File.WriteAllText(path + name + ".py", thisPythonString);
            try
            {
                RunningPythonProcess.StartInfo.Arguments = path + name + ".py";
                RunningPythonProcess.Start();

                // To avoid deadlocks, always read the output stream first and then wait.
                output += RunningPythonProcess.StandardOutput.ReadToEnd();
                output += RunningPythonProcess.StandardError.ReadToEnd();
                RunningPythonProcess.WaitForExit();
                System.IO.File.Delete(path + name + ".py");


                PythonIDE.console.Text = output;

                doc.Load(path + "_PythonExecutionOrder_" + thisIndex.ToString() + ".xml");

                for (int i3 = 0; i3 < Params.Output.Count; i3++)
                {
                    DA.SetData(i3, doc.DocumentElement.SelectSingleNode("/result/" + Params.Output[i3].Name).InnerText);
                }
                System.IO.File.Delete(path + "_PythonExecutionOrder_" + thisIndex.ToString() + ".xml");
            }catch (Exception exf)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, output + "\n\n" + exf.ToString());
            }
        }
Пример #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void Gh_CPythonComponent_PreviewExpired(IGH_DocumentObject sender, GH_PreviewExpiredEventArgs e)
 {
     try
     {
         if (Globals.OpenThisShell[thisIndex] == true)
         {
             PythonIDE.Show();
         }
         else
         {
             PythonIDE.Hide();
         }
     }
     catch (Exception exc)
     {
         MessageBox.Show(exc.ToString());
     }
     AddNamesAndDescriptions();
     Grasshopper.Instances.RedrawCanvas();
 }