|
| 1 | +/* |
| 2 | + * This file is part of the Buildings and Habitats object Model (BHoM) |
| 3 | + * Copyright (c) 2015 - 2023, the respective contributors. All rights reserved. |
| 4 | + * |
| 5 | + * Each contributor holds copyright over their respective contributions. |
| 6 | + * The project versioning (Git) records all such contribution source information. |
| 7 | + * |
| 8 | + * |
| 9 | + * The BHoM is free software: you can redistribute it and/or modify |
| 10 | + * it under the terms of the GNU Lesser General Public License as published by |
| 11 | + * the Free Software Foundation, either version 3.0 of the License, or |
| 12 | + * (at your option) any later version. |
| 13 | + * |
| 14 | + * The BHoM is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + * GNU Lesser General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU Lesser General Public License |
| 20 | + * along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>. |
| 21 | + */ |
| 22 | + |
| 23 | +using BH.oM.Base.Attributes; |
| 24 | +using BH.oM.LadybugTools; |
| 25 | +using System.Linq; |
| 26 | +using System.Collections.Generic; |
| 27 | +using System.ComponentModel; |
| 28 | +using BH.oM.Python; |
| 29 | +using System.IO; |
| 30 | +using System; |
| 31 | + |
| 32 | +namespace BH.Engine.LadybugTools |
| 33 | +{ |
| 34 | + public static partial class Query |
| 35 | + { |
| 36 | + [Description("Returns a list of materials from the Python Materials list.")] |
| 37 | + [Input("filter", "Text to filter the resultant list by. Filter applies to the material identifier. Leave blank to return all materials.")] |
| 38 | + [Output("materials", "A list of materials.")] |
| 39 | + public static List<IEnergyMaterialOpaque> GetMaterial(string filter = "") |
| 40 | + { |
| 41 | + PythonEnvironment env = Compute.InstallPythonEnv_LBT(true); |
| 42 | + |
| 43 | + string jsonFile = Path.Combine(Path.GetTempPath(), $"LBTBHoM_Materials_{DateTime.Now:yyyyMMdd}.json"); |
| 44 | + |
| 45 | + if (!File.Exists(jsonFile)) |
| 46 | + { |
| 47 | + string script = Path.Combine(Python.Query.DirectoryCode(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped", "get_material.py"); |
| 48 | + |
| 49 | + string command = $"{env.Executable} {script} -j \"{jsonFile}\""; |
| 50 | + |
| 51 | + Python.Compute.RunCommandStdout(command: command, hideWindows: true); |
| 52 | + } |
| 53 | + |
| 54 | + string jsonContent = File.ReadAllText(jsonFile); |
| 55 | + |
| 56 | + List<object> materials = (List<object>)BH.Engine.Serialiser.Convert.FromJsonArray(jsonContent); |
| 57 | + |
| 58 | + List<IEnergyMaterialOpaque> materialObjects = new List<IEnergyMaterialOpaque>(); |
| 59 | + foreach (object materialObject in materials) |
| 60 | + { |
| 61 | + materialObjects.Add((IEnergyMaterialOpaque)materialObject); |
| 62 | + } |
| 63 | + |
| 64 | + return materialObjects.Where(m => m.Identifier.Contains(filter)).ToList(); |
| 65 | + } |
| 66 | + } |
| 67 | +} |
0 commit comments