diff --git a/LadybugTools_Engine/Python/src/ladybugtools_toolkit/bhom/wrapped/get_typology.py b/LadybugTools_Engine/Python/src/ladybugtools_toolkit/bhom/wrapped/get_typology.py index 7ebf2ea0..46c7cd30 100644 --- a/LadybugTools_Engine/Python/src/ladybugtools_toolkit/bhom/wrapped/get_typology.py +++ b/LadybugTools_Engine/Python/src/ladybugtools_toolkit/bhom/wrapped/get_typology.py @@ -1,4 +1,4 @@ -"""Method to wrap for access to pre-defined materials.""" +"""Method to wrap for access to pre-defined typologies.""" # pylint: disable=C0415,E0401,W0703 import argparse import traceback diff --git a/LadybugTools_Engine/Query/GetMaterial.cs b/LadybugTools_Engine/Query/GetMaterial.cs new file mode 100644 index 00000000..24882362 --- /dev/null +++ b/LadybugTools_Engine/Query/GetMaterial.cs @@ -0,0 +1,67 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2023, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using BH.oM.Base.Attributes; +using BH.oM.LadybugTools; +using System.Linq; +using System.Collections.Generic; +using System.ComponentModel; +using BH.oM.Python; +using System.IO; +using System; + +namespace BH.Engine.LadybugTools +{ + public static partial class Query + { + [Description("Returns a list of materials from the Python Materials list.")] + [Input("filter", "Text to filter the resultant list by. Filter applies to the material identifier. Leave blank to return all materials.")] + [Output("materials", "A list of materials.")] + public static List GetMaterial(string filter = "") + { + PythonEnvironment env = Compute.InstallPythonEnv_LBT(true); + + string jsonFile = Path.Combine(Path.GetTempPath(), $"LBTBHoM_Materials_{DateTime.Now:yyyyMMdd}.json"); + + if (!File.Exists(jsonFile)) + { + string script = Path.Combine(Python.Query.DirectoryCode(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped", "get_material.py"); + + string command = $"{env.Executable} {script} -j \"{jsonFile}\""; + + Python.Compute.RunCommandStdout(command: command, hideWindows: true); + } + + string jsonContent = File.ReadAllText(jsonFile); + + List materials = (List)BH.Engine.Serialiser.Convert.FromJsonArray(jsonContent); + + List materialObjects = new List(); + foreach (object materialObject in materials) + { + materialObjects.Add((IEnergyMaterialOpaque)materialObject); + } + + return materialObjects.Where(m => m.Identifier.Contains(filter)).ToList(); + } + } +} diff --git a/LadybugTools_Engine/Query/GetTypology.cs b/LadybugTools_Engine/Query/GetTypology.cs new file mode 100644 index 00000000..c4e9fe0b --- /dev/null +++ b/LadybugTools_Engine/Query/GetTypology.cs @@ -0,0 +1,67 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2023, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using BH.oM.Base.Attributes; +using BH.oM.LadybugTools; +using System.Linq; +using System.Collections.Generic; +using System.ComponentModel; +using BH.oM.Python; +using System.IO; +using System; + +namespace BH.Engine.LadybugTools +{ + public static partial class Query + { + [Description("Returns a list of Typology objects from the Python predefined Typologies list.")] + [Input("filter", "Text to filter the resultant list by. Filter applies to the typology identifier. Leave blank to return all typologies.")] + [Output("typologies", "A list of Typology objects.")] + public static List GetTypology(string filter = "") + { + PythonEnvironment env = Compute.InstallPythonEnv_LBT(true); + + string jsonFile = Path.Combine(Path.GetTempPath(), $"LBTBHoM_Typologies_{DateTime.Now:yyyyMMdd}.json"); + + if (!File.Exists(jsonFile)) + { + string script = Path.Combine(Python.Query.DirectoryCode(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped", "get_typology.py"); + + string command = $"{env.Executable} {script} -j \"{jsonFile}\""; + + Python.Compute.RunCommandStdout(command: command, hideWindows: true); + } + + string jsonContent = File.ReadAllText(jsonFile); + + List typologies = (List)BH.Engine.Serialiser.Convert.FromJsonArray(jsonContent); + + List typologyObjects = new List(); + foreach (object typologyObject in typologies) + { + typologyObjects.Add((Typology)typologyObject); + } + + return typologyObjects.Where(m => m.Identifier.Contains(filter)).ToList(); + } + } +} diff --git a/LadybugTools_Engine/Versioning_70.json b/LadybugTools_Engine/Versioning_70.json index 14344d48..106743df 100644 --- a/LadybugTools_Engine/Versioning_70.json +++ b/LadybugTools_Engine/Versioning_70.json @@ -4,8 +4,6 @@ "BH.Engine.LadybugTools.Create.Typology(System.Collections.Generic.List, System.String, System.Double, System.Double, System.Double)": "This method only did validation for creating the object, which has been moved to methods that take a Typology as an input.", "BH.Engine.LadybugTools.Convert.SnakeCaseToPascalCase(System.String)": "This method and other case conversion methods in the LBT Toolkit have been replaced by a single method that can do case conversions when given a case type.", "BH.Engine.LadybugTools.Convert.PascalCaseToSnakeCase(System.String)": "This method and other case conversion methods in the LBT Toolkit have been replaced by a single method that can do case conversions when given a case type.", - "BH.Engine.LadybugTools.Query.GetMaterial(System.String)": "Due to a refactor of the underlying python libraries, this method was broken. To get materials for use within python scripts, get them within the scripts.", - "BH.Engine.LadybugTools.Query.GetTypology(System.String)": "Due to a refactor of the underlying python libraries, this method was broken. To get typologies for use within python scripts, get them within the scripts.", "BH.Engine.LadybugTools.Compute.EPWtoCustomObject(System.String)": "Due to inclusion of EPW as an object, this method is no longer required and has been removed." } } \ No newline at end of file