Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Revit_Core_Adapter/Listener/RevitListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
101 changes: 101 additions & 0 deletions Revit_Core_Engine/Objects/Initialisation.cs
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

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<CodeElementRecord> CodeElements { get; private set; } = new List<CodeElementRecord>();

public static AssemblyResolver AssemblyResolver { get; private set; } = new AssemblyResolver();


/***************************************************/
/**** Public methods ****/
/***************************************************/

public static bool LoadCodeElements(int revitVersion)

Check warning on line 50 in Revit_Core_Engine/Objects/Initialisation.cs

View check run for this annotation

BHoMBot-CI / documentation-compliance

Revit_Core_Engine/Objects/Initialisation.cs#L50

Input parameter requires a matching Input attribute - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/IsInputAttributePresent
{
List<CodeElementRecord> 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<CodeElementRecord> 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)

Check warning on line 87 in Revit_Core_Engine/Objects/Initialisation.cs

View check run for this annotation

BHoMBot-CI / documentation-compliance

Revit_Core_Engine/Objects/Initialisation.cs#L87

Input parameter requires a matching Input attribute - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/IsInputAttributePresent
{
bool success = LoadCodeElements(revitVersion);

AssemblyResolver = BH.Engine.Base.Objects.Initialisation.CreateAssemblyResolver(CodeElements);
BH.Engine.Base.Compute.SetAssemblyResolver(AssemblyResolver);

CompletionTime = DateTime.UtcNow;

return success;
}

/***************************************************/
}
}
22 changes: 5 additions & 17 deletions Revit_Core_Engine/Revit_Core_Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,6 @@
<ProjectReference Include="..\Revit_Engine\Revit_Engine.csproj" />
<ProjectReference Include="..\Revit_oM\Revit_oM.csproj" />
</ItemGroup>

<Target Name="ForceReferences" BeforeTargets="CoreCompile">
<WriteLinesToFile File="$(IntermediateOutputPath)ForceRefs.g.cs" Lines="@(ReferencePath->'[assembly: System.Reflection.AssemblyMetadata(&quot;UsedRef&quot;, &quot;%(Filename)&quot;)]')" Overwrite="true" />
<ItemGroup>
<Compile Include="$(IntermediateOutputPath)ForceRefs.g.cs" />
</ItemGroup>
</Target>

<ItemGroup>
<Reference Include="RevitAPI">
Expand All @@ -87,11 +80,6 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Reference Include="Analytical_Engine">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(ProgramData)\BHoM\Assemblies\Analytical_Engine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Analytical_oM">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(ProgramData)\BHoM\Assemblies\Analytical_oM.dll</HintPath>
Expand Down Expand Up @@ -132,11 +120,6 @@
<HintPath>$(ProgramData)\BHoM\Assemblies\Diffing_Engine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Dimensional_Engine">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(ProgramData)\BHoM\Assemblies\Dimensional_Engine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Dimensional_oM">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(ProgramData)\BHoM\Assemblies\Dimensional_oM.dll</HintPath>
Expand Down Expand Up @@ -217,6 +200,11 @@
<HintPath>$(ProgramData)\BHoM\Assemblies\Physical_oM.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Reflection_Engine">
<HintPath>$(ProgramData)\BHoM\Assemblies\Reflection_Engine.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Spatial_Engine">
<HintPath>$(ProgramData)\BHoM\Assemblies\Spatial_Engine.dll</HintPath>
<Private>False</Private>
Expand Down
Loading