Skip to content

Commit 6df1a6b

Browse files
authored
7.3 Deployment (#245)
2 parents 658da8f + af8c254 commit 6df1a6b

37 files changed

Lines changed: 1307 additions & 121 deletions

.ci/BHoMBot/Nuget/BHoM.Interop.LadybugTools.nuspec

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
<file src="licence/licence.txt" target="" />
2929
<file src="images/icon.png" target="" />
3030
<file src="docs/readme.md" target="" />
31-
<!--lib\**\* is a workaround for contentfiles not including dll files-->
32-
<file src="lib\**\*" target="lib" />
33-
<file src="C:\ProgramData\BHoM\Extensions\PythonCode\LadybugTools_Toolkit\src\ladybugtools_toolkit\bhom\wrapped\**\*.*" exclude="**\__pycache__\*;**\docs\**\*" target="contentFiles\any\any\PythonCode\LadybugTools_Toolkit\src\ladybugtools_toolkit\bhom\wrapped"/>
34-
<file src="C:\ProgramData\BHoM\Extensions\PythonCode\LadybugTools_Toolkit\src\**\*.*" exclude="**\__pycache__\*;**\docs\**\*" target="contentFiles\any\any\PythonEnvironment\Lib\site-packages" />
31+
<file src="C:\ProgramData\BHoM\Extensions\PythonCode\LadybugTools_Toolkit\src\ladybugtools_toolkit\bhom\wrapped\**\*.*" exclude="**\__pycache__\*;**\docs\**\*" target="contentFiles\any\any\PythonCode\LadybugTools_Toolkit\src\ladybugtools_toolkit\bhom\wrapped"/>
32+
<file src="C:\ProgramData\BHoM\Extensions\PythonCode\LadybugTools_Toolkit\src\**\*.*" exclude="**\__pycache__\*;**\docs\**\*" target="contentFiles\any\any\PythonEnvironment\Lib\site-packages" />
3533
</files>
3634
</package>

LadybugTools_Adapter/AdapterActions/Execute.cs

Lines changed: 81 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
using BH.Engine.Base;
3838
using System.Drawing;
3939
using BH.Engine.Serialiser;
40-
using BH.Engine.LadyBugTools;
4140
using System.Reflection;
4241

4342
namespace BH.Adapter.LadybugTools
@@ -312,12 +311,25 @@ private List<object> RunCommand(HeatPlotCommand command, ActionConfig actionConf
312311
if (colourMap.ColourMapValidity())
313312
colourMap = colourMap.ToColourMap().FromColourMap();
314313

314+
string returnFile = Path.GetTempFileName();
315+
315316
// run the process
316-
string cmdCommand = $"{m_environment.Executable} {script} -e \"{epwFile}\" -dtk \"{command.EPWKey.ToText()}\" -cmap \"{colourMap}\" -p \"{command.OutputLocation}\"";
317+
string cmdCommand = $"{m_environment.Executable} {script} -e \"{epwFile}\" -dtk \"{command.EPWKey.ToText()}\" -cmap \"{colourMap}\" -r \"{returnFile.Replace('\\', '/')}\" -p \"{command.OutputLocation}\"";
317318
string result = Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true);
318319

320+
if (!File.Exists(result))
321+
{
322+
BH.Engine.Base.Compute.RecordError($"An error occurred while running the command: {result}");
323+
File.Delete(returnFile);
324+
return new List<object>();
325+
}
326+
327+
CustomObject obj = (CustomObject)BH.Engine.Serialiser.Convert.FromJson(System.IO.File.ReadAllText(returnFile));
328+
File.Delete(returnFile);
329+
PlotInformation info = Convert.ToPlotInformation(obj, new CollectionData());
330+
319331
m_executeSuccess = true;
320-
return new List<object>() { result };
332+
return new List<object>() { info };
321333
}
322334

323335
/**************************************************/
@@ -351,12 +363,25 @@ private List<object> RunCommand(WindroseCommand command, ActionConfig actionConf
351363
if (colourMap.ColourMapValidity())
352364
colourMap = colourMap.ToColourMap().FromColourMap();
353365

366+
string returnFile = Path.GetTempFileName();
367+
354368
// run the process
355-
string cmdCommand = $"{m_environment.Executable} {script} -e \"{epwFile}\" -ap \"{command.AnalysisPeriod.FromBHoM().Replace("\"", "\\\"")}\" -cmap \"{colourMap}\" -bins \"{command.NumberOfDirectionBins}\" -p \"{command.OutputLocation}\"";
369+
string cmdCommand = $"{m_environment.Executable} {script} -e \"{epwFile}\" -ap \"{command.AnalysisPeriod.FromBHoM().Replace("\"", "\\\"")}\" -cmap \"{colourMap}\" -bins \"{command.NumberOfDirectionBins}\" -r \"{returnFile.Replace('\\', '/')}\" -p \"{command.OutputLocation}\"";
356370
string result = Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true);
357371

372+
if (!File.Exists(result))
373+
{
374+
BH.Engine.Base.Compute.RecordError($"An error occurred while running the command: {result}");
375+
File.Delete(returnFile);
376+
return new List<object>();
377+
}
378+
379+
CustomObject obj = (CustomObject)BH.Engine.Serialiser.Convert.FromJson(System.IO.File.ReadAllText(returnFile));
380+
File.Delete(returnFile);
381+
PlotInformation info = Convert.ToPlotInformation(obj, new WindroseData());
382+
358383
m_executeSuccess = true;
359-
return new List<object> { result };
384+
return new List<object> { info };
360385
}
361386

362387
/**************************************************/
@@ -397,6 +422,7 @@ private List<object> RunCommand(UTCIHeatPlotCommand command, ActionConfig action
397422
BH.Engine.Base.Compute.RecordError($"When overriding bin colours 10 colours must be provided, but {command.BinColours.Count} colours were provided instead.");
398423
return null;
399424
}
425+
400426
List<string> colours = command.BinColours.Select(x => x.ToHexCode()).ToList();
401427

402428
string hexColours = $"[\"{string.Join("\",\"", colours)}\"]";
@@ -418,25 +444,29 @@ private List<object> RunCommand(UTCIHeatPlotCommand command, ActionConfig action
418444

419445
string script = Path.Combine(Engine.LadybugTools.Query.PythonCodeDirectory(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped\\plot", "utci_heatmap.py");
420446

447+
string returnFile = Path.GetTempFileName();
448+
421449
// run the process
422-
string cmdCommand = $"{m_environment.Executable} \"{script}\" -e \"{epwFile}\" -in \"{argFile}\" -ws \"{command.WindSpeedMultiplier}\" -sp \"{command.OutputLocation}\"";
423-
string result = "";
450+
string cmdCommand = $"{m_environment.Executable} \"{script}\" -e \"{epwFile}\" -in \"{argFile}\" -ws \"{command.WindSpeedMultiplier}\" -r \"{returnFile.Replace('\\', '/')}\" -sp \"{command.OutputLocation}\"";
451+
string result = Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true);
424452

425-
try
426-
{
427-
result = Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true);
428-
}
429-
catch (Exception ex)
430-
{
431-
BH.Engine.Base.Compute.RecordError(ex, "An error occurred while running some python.");
432-
}
433-
finally
453+
string resultFile = result.Split('\n').Last();
454+
455+
if (!File.Exists(resultFile))
434456
{
457+
BH.Engine.Base.Compute.RecordError($"An error occurred while running the command: {result}");
458+
File.Delete(returnFile);
435459
File.Delete(argFile);
460+
return new List<object>();
436461
}
437462

463+
CustomObject obj = (CustomObject)BH.Engine.Serialiser.Convert.FromJson(System.IO.File.ReadAllText(returnFile));
464+
File.Delete(returnFile);
465+
File.Delete(argFile);
466+
PlotInformation info = Convert.ToPlotInformation(obj, new UTCIData());
467+
438468
m_executeSuccess = true;
439-
return new List<object> { result.Split('\n').Last() };
469+
return new List<object> { info };
440470
}
441471

442472
/**************************************************/
@@ -473,12 +503,27 @@ private List<object> RunCommand(DiurnalPlotCommand command, ActionConfig actionC
473503

474504
string script = Path.Combine(Engine.LadybugTools.Query.PythonCodeDirectory(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped\\plot", "diurnal.py");
475505

506+
string returnFile = Path.GetTempFileName();
507+
476508
// run the process
477-
string cmdCommand = $"{m_environment.Executable} {script} -e \"{epwFile}\" -dtk \"{command.EPWKey.ToText()}\" -c \"{command.Colour.ToHexCode()}\" -t \"{command.Title}\" -ap \"{command.Period.ToString().ToLower()}\" -p \"{command.OutputLocation}\"";
509+
string cmdCommand = $"{m_environment.Executable} {script} -e \"{epwFile}\" -dtk \"{command.EPWKey.ToText()}\" -c \"{command.Colour.ToHexCode()}\" -t \"{command.Title}\" -ap \"{command.Period.ToString().ToLower()}\" -r \"{returnFile.Replace('\\', '/')}\" -p \"{command.OutputLocation}\"";
478510
string result = Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true);
479511

512+
string resultFile = result.Split('\n').Last();
513+
514+
if (!File.Exists(resultFile))
515+
{
516+
BH.Engine.Base.Compute.RecordError($"An error occurred while running the command: {result}");
517+
File.Delete(returnFile);
518+
return new List<object>();
519+
}
520+
521+
CustomObject obj = (CustomObject)BH.Engine.Serialiser.Convert.FromJson(System.IO.File.ReadAllText(returnFile));
522+
File.Delete(returnFile);
523+
PlotInformation info = Convert.ToPlotInformation(obj, new CollectionData());
524+
480525
m_executeSuccess = true;
481-
return new List<object>() { result.Split('\n').Last() };
526+
return new List<object>() { info };
482527
}
483528

484529
/**************************************************/
@@ -513,12 +558,27 @@ private List<object> RunCommand(SunPathPlotCommand command, ActionConfig actionC
513558

514559
string script = Path.Combine(Engine.LadybugTools.Query.PythonCodeDirectory(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped\\plot", "sunpath.py");
515560

561+
string returnFile = Path.GetTempFileName();
562+
516563
//run the process
517-
string cmdCommand = $"{m_environment.Executable} {script} -e \"{epwFile}\" -s {command.SunSize} -ap \"{command.AnalysisPeriod.FromBHoM().Replace("\"", "\\\"")}\" -p \"{command.OutputLocation}\"";
564+
string cmdCommand = $"{m_environment.Executable} {script} -e \"{epwFile}\" -s {command.SunSize} -ap \"{command.AnalysisPeriod.FromBHoM().Replace("\"", "\\\"")}\" -r \"{returnFile.Replace('\\', '/')}\" -p \"{command.OutputLocation}\"";
518565
string result = Engine.Python.Compute.RunCommandStdout(cmdCommand, hideWindows: true);
519566

567+
string resultFile = result.Split('\n').Last();
568+
569+
if (!File.Exists(resultFile))
570+
{
571+
BH.Engine.Base.Compute.RecordError($"An error occurred while running the command: {result}");
572+
File.Delete(returnFile);
573+
return new List<object>();
574+
}
575+
576+
CustomObject obj = (CustomObject)BH.Engine.Serialiser.Convert.FromJson(System.IO.File.ReadAllText(returnFile));
577+
File.Delete(returnFile);
578+
PlotInformation info = Convert.ToPlotInformation(obj, new SunPathData());
579+
520580
m_executeSuccess = true;
521-
return new List<object>() { result.Split('\n').Last() };
581+
return new List<object>() { info };
522582
}
523583

524584
/**************************************************/

0 commit comments

Comments
 (0)