////////////////////////////////////////////////////////////// // Copyright file = "OpenBlender.cs" // // Copyright (c) 2020 All Rights Reserved // // Authors: Francine Rotzetter / Robin Dittli // // Date: 21/01/2020 // // Summary: Class representing an initialized process // ////////////////////////////////////////////////////////////// /* . . . _ . . ( (_) . . . . ____.--^. . /: / | + . . /: `--=--' . . /: __[\==`-.___ * . /__|\ _~~~~~~ ~~--..__ . . \ \|::::|-----.....___|~--. . \ _\_~~~~~-----:|:::______//---...___ . [\ \ __ -- \ ~ \_ ~~~===------==-...____ [============================================================- / __/__ -- /__ -- /____....----''''~~~~ . * / / == ____....=---='''~~~~ . /____....--=-''':~~~~ . . . ~--~ . . . . . + . + . <=> . . . . * . * ` - */ using System; using System.Diagnostics; namespace THUMM { //Runs Blender through command line //Provides Blender with arguments (expandable in future) //Runs python files within arguments // public class OpenBlender { //Fields //Create new Process which opens cmd.exe private Process openBlender; //Assigns start directory to process private string changeDir; //Backing Field private string _blenderInstallFolder; //BlenderSpplication Folder public string BlenderInstallFolder { get { return _blenderInstallFolder; } set { _blenderInstallFolder = value; } } //constructor public OpenBlender() { changeDir = "C:"; } //Create and start process public void OpeningBlender() { //Create Process openBlender = new Process(); SetUpStartInfo(); //Enable Process.Exited functionality openBlender.EnableRaisingEvents = true; //Starts the Process try { openBlender.Start(); } catch (BlenderCMDExceptions e) { Console.WriteLine("Blender failed to start: " + e); return; } //Wait for cmd to close try { //In case delay is needed upon exiting the cmd.exe openBlender.WaitForExit(); } catch (BlenderCMDExceptions e) { Console.WriteLine("Blender encountered a problem: " + e); return; } //Set up callback //Create Event handler for on Exit of the program //That way we can execute another function if needed openBlender.Exited += new EventHandler(openedBlender_Exited); } //SetUp StartInfo //Apply arguments //!!!Not ideal coupling with AddPythonScript -> Put later in struct! private void SetUpStartInfo() { ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = @"cmd.exe"; startInfo.WorkingDirectory = changeDir; //Supply arguments to cmd.exe //Execute certain commands in order startInfo.Arguments = "/C " + @"cd " + LocalPaths.BlenderInstallFolderPath + "&&" + "blender -P " + LocalPaths.PyFolderPath + @"\" + AddPythonScript.PyFileName; Console.WriteLine(startInfo.Arguments); //Apply StartInfos to Process openBlender.StartInfo = startInfo; } //Commence with next task if needed (not yet implemented) private void openedBlender_Exited(object sender, EventArgs e) { //MessageBox.Show("cmd.exe is closed"); } } }