diff --git a/Revit_Core_Adapter/Listener/RevitListener.cs b/Revit_Core_Adapter/Listener/RevitListener.cs index 9a4d7537c..6393405b3 100644 --- a/Revit_Core_Adapter/Listener/RevitListener.cs +++ b/Revit_Core_Adapter/Listener/RevitListener.cs @@ -162,6 +162,10 @@ public Result OnShutdown(UIControlledApplication application) public Result OnStartup(UIControlledApplication uIControlledApplication) { + int version = int.Parse(uIControlledApplication.ControlledApplication.VersionNumber.Substring(0, 4)); + if (!BH.Revit.Engine.Core.Initialisation.Activate(version)) + BH.Engine.Base.Compute.RecordError("Revit Engine initialisation failed. Revit adapter will not work properly."); + // Load sensitive Dynamo assemblies prior to BHoM to prevent the former from crashing. BH.Revit.Engine.Core.Compute.LoadSensitiveDynamoAssemblies(); diff --git a/Revit_Core_Engine/Objects/Initialisation.cs b/Revit_Core_Engine/Objects/Initialisation.cs new file mode 100644 index 000000000..86f61902f --- /dev/null +++ b/Revit_Core_Engine/Objects/Initialisation.cs @@ -0,0 +1,101 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2026, 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.Engine.Base.Objects; +using BH.oM.Base.Reflection; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text.RegularExpressions; + +namespace BH.Revit.Engine.Core +{ + public static class Initialisation + { + /***************************************************/ + /**** Public properties ****/ + /***************************************************/ + + public static DateTime? CompletionTime { get; set; } = null; + + public static List CodeElements { get; private set; } = new List(); + + public static AssemblyResolver AssemblyResolver { get; private set; } = new AssemblyResolver(); + + + /***************************************************/ + /**** Public methods ****/ + /***************************************************/ + + public static bool LoadCodeElements(int revitVersion) + { + List flow1 = BH.Engine.Base.Objects.Initialisation.LoadCodeElements( + BH.Engine.Base.Objects.Initialisation.DefaultAssemblyContentFilePath, + x => x.FromTsv()); + + flow1 = BH.Engine.Base.Objects.Initialisation.RefreshFromNewAssemblies( + flow1, + BH.Engine.Base.Objects.Initialisation.DefaultAssemblyNameFilter, + BH.Engine.Base.Objects.Initialisation.DefaultAssemblyContentFilePath, + x => x.ToTsv(), + names => BH.Engine.Reflection.Query.CodeElements(names)); + + string tsvPath = Path.Combine( + BH.Engine.Base.Query.BHoMFolderResources(), + "Revit", + "AssemblyContent", + revitVersion.ToString(), + $"Revit_Core_Engine_{revitVersion}.tsv"); + + Regex filter = new Regex($"^Revit_Core_Engine_{revitVersion}$"); + + List flow2 = BH.Engine.Base.Objects.Initialisation.LoadCodeElements(tsvPath, x => x.FromTsv()); + + flow2 = BH.Engine.Base.Objects.Initialisation.RefreshFromNewAssemblies( + flow2, + filter, + tsvPath, + x => x.ToTsv(), + names => BH.Engine.Reflection.Query.CodeElements(names)); + + CodeElements = flow1.Concat(flow2).ToList(); + return true; + } + + /***************************************************/ + + public static bool Activate(int revitVersion) + { + bool success = LoadCodeElements(revitVersion); + + AssemblyResolver = BH.Engine.Base.Objects.Initialisation.CreateAssemblyResolver(CodeElements); + BH.Engine.Base.Compute.SetAssemblyResolver(AssemblyResolver); + + CompletionTime = DateTime.UtcNow; + + return success; + } + + /***************************************************/ + } +} diff --git a/Revit_Core_Engine/Revit_Core_Engine.csproj b/Revit_Core_Engine/Revit_Core_Engine.csproj index ed8296864..1729aabc9 100644 --- a/Revit_Core_Engine/Revit_Core_Engine.csproj +++ b/Revit_Core_Engine/Revit_Core_Engine.csproj @@ -68,13 +68,6 @@ - - - - - - - @@ -87,11 +80,6 @@ - - False - $(ProgramData)\BHoM\Assemblies\Analytical_Engine.dll - False - False $(ProgramData)\BHoM\Assemblies\Analytical_oM.dll @@ -132,11 +120,6 @@ $(ProgramData)\BHoM\Assemblies\Diffing_Engine.dll False - - False - $(ProgramData)\BHoM\Assemblies\Dimensional_Engine.dll - False - False $(ProgramData)\BHoM\Assemblies\Dimensional_oM.dll @@ -217,6 +200,11 @@ $(ProgramData)\BHoM\Assemblies\Physical_oM.dll False + + $(ProgramData)\BHoM\Assemblies\Reflection_Engine.dll + False + False + $(ProgramData)\BHoM\Assemblies\Spatial_Engine.dll False