protected override void SolveInstance(IGH_DataAccess DA) { Machina.Robot bot = null; List <Machina.Action> actions = new List <Machina.Action>(); bool inline = false; bool comments = false; if (!DA.GetData(0, ref bot)) { return; } if (!DA.GetDataList(1, actions)) { return; } if (!DA.GetData(2, ref inline)) { return; } if (!DA.GetData(3, ref comments)) { return; } // Sanity, avoid users compiling programs with inadvertedly null actions. foreach (var a in actions) { if (a == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Can't compile a Program with `null` Actions, please review the Action list."); return; } } // Create a new instance to avoid inheriting robot states between different compilations // https://github.com/RobotExMachina/Machina-Grasshopper/issues/3 Machina.Robot compiler = Machina.Robot.Create(bot.Name, bot.Brand); compiler.ControlMode(ControlType.Offline); foreach (Machina.Action a in actions) { compiler.Issue(a); } Machina.Types.Data.RobotProgram program = compiler.Compile(inline, comments); DA.SetData(0, program); }
protected override void SolveInstance(IGH_DataAccess DA) { Machina.Robot bot = null; List <Machina.Action> actions = new List <Machina.Action>(); bool inline = false; bool comments = false; if (!DA.GetData(0, ref bot)) { return; } if (!DA.GetDataList(1, actions)) { return; } if (!DA.GetData(2, ref inline)) { return; } if (!DA.GetData(3, ref comments)) { return; } // Create a new instance to avoid inheriting robot states between different compilations // https://github.com/RobotExMachina/Machina-Grasshopper/issues/3 Machina.Robot compiler = Machina.Robot.Create(bot.Name, bot.Brand); compiler.ControlMode(ControlType.Offline); foreach (Machina.Action a in actions) { compiler.Do(a); } List <string> codeLines = compiler.Compile(inline, comments); // I forgot why I chose to spit out one single string, but this makes the panel super freaking heavy. Reverting. //StringWriter writer = new StringWriter(); //for (var i = 0; i < codeLines.Count; i++) //{ // writer.WriteLine(codeLines[i]); //} //string code = writer.ToString(); DA.SetDataList(0, codeLines); }
protected override void SolveInstance(IGH_DataAccess DA) { Machina.Robot bot = null; List <Machina.Action> actions = new List <Machina.Action>(); bool inline = false; bool comments = false; if (!DA.GetData(0, ref bot)) { return; } if (!DA.GetDataList(1, actions)) { return; } if (!DA.GetData(2, ref inline)) { return; } if (!DA.GetData(3, ref comments)) { return; } //bot.Mode(Machina.ControlMode.Offline); bot.ControlMode(ControlType.Offline); foreach (Machina.Action a in actions) { bot.Do(a); } List <string> codeLines = bot.Export(inline, comments); StringWriter writer = new StringWriter(); for (var i = 0; i < codeLines.Count; i++) { writer.WriteLine(codeLines[i]); } string code = writer.ToString(); DA.SetData(0, code); }