Skip to content

Commit d129a6c

Browse files
authored
Merge pull request #2137 from mjkkirschner/Revit2019_libGLoading
Revit2019 lib g loading
2 parents 161fb73 + ac93a10 commit d129a6c

5 files changed

Lines changed: 58 additions & 17 deletions

File tree

src/DynamoRevit/DynamoRevit.cs

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ public class JournalNodeKeys
182182
Regeneration(RegenerationOption.Manual)]
183183
public class DynamoRevit : IExternalCommand
184184
{
185-
enum Versions { ShapeManager = 224 };
186185

187186
/// <summary>
188187
/// Based on the RevitDynamoModelState a dependent component can take certain
@@ -233,7 +232,7 @@ private void AssemblyLoad(object sender, AssemblyLoadEventArgs args)
233232
}
234233

235234
public Result ExecuteCommand(DynamoRevitCommandData commandData)
236-
{
235+
{
237236
var startupTimer = Stopwatch.StartNew();
238237
if (ModelState == RevitDynamoModelState.StartedUIless)
239238
{
@@ -374,6 +373,7 @@ public static RevitDynamoModel RevitDynamoModel
374373
/// located.</param>
375374
/// <returns>Returns the full path to geometry factory assembly.</returns>
376375
///
376+
[Obsolete("Please use the overload which specifies the version of the geometry library to load")]
377377
public static string GetGeometryFactoryPath(string corePath)
378378
{
379379
var dynamoAsmPath = Path.Combine(corePath, "DynamoShapeManager.dll");
@@ -382,12 +382,30 @@ public static string GetGeometryFactoryPath(string corePath)
382382
throw new FileNotFoundException("File not found", dynamoAsmPath);
383383

384384
var utilities = assembly.GetType("DynamoShapeManager.Utilities");
385-
var getGeometryFactoryPath = utilities.GetMethod("GetGeometryFactoryPath");
385+
var getGeometryFactoryPath = utilities.GetMethod("GetGeometryFactoryPath2");
386+
387+
//if old method is called default to 224.4.0
388+
return (getGeometryFactoryPath.Invoke(null,
389+
new object[] { corePath, new Version(224,4,0) }) as string);
390+
}
391+
392+
393+
public static string GetGeometryFactoryPath(string corePath,Version version)
394+
{
395+
var dynamoAsmPath = Path.Combine(corePath, "DynamoShapeManager.dll");
396+
var assembly = Assembly.LoadFrom(dynamoAsmPath);
397+
if (assembly == null)
398+
throw new FileNotFoundException("File not found", dynamoAsmPath);
399+
400+
var utilities = assembly.GetType("DynamoShapeManager.Utilities");
401+
var getGeometryFactoryPath = utilities.GetMethod("GetGeometryFactoryPath2");
386402

387403
return (getGeometryFactoryPath.Invoke(null,
388-
new object[] { corePath, Versions.ShapeManager }) as string);
404+
new object[] { corePath, version }) as string);
389405
}
390406

407+
408+
391409
private static void PreloadDynamoCoreDlls()
392410
{
393411
// Assume Revit Install folder as look for root. Assembly name is compromised.
@@ -414,11 +432,11 @@ private static RevitDynamoModel InitializeCoreModel(DynamoRevitCommandData comma
414432
var dynamoRevitRoot = Path.GetDirectoryName(dynamoRevitExePath);// ...\Revit_xxxx\ folder
415433

416434
// get Dynamo Revit Version
417-
var revitVersion = Assembly.GetExecutingAssembly().GetName().Version;
435+
var dynRevitVersion = Assembly.GetExecutingAssembly().GetName().Version;
418436

419437
var umConfig = UpdateManagerConfiguration.GetSettings(new DynamoRevitLookUp());
420438
var revitUpdateManager = new DynUpdateManager(umConfig);
421-
revitUpdateManager.HostVersion = revitVersion; // update RevitUpdateManager with the current DynamoRevit Version
439+
revitUpdateManager.HostVersion = dynRevitVersion; // update RevitUpdateManager with the current DynamoRevit Version
422440
revitUpdateManager.HostName = "Dynamo Revit";
423441

424442
Debug.Assert(umConfig.DynamoLookUp != null);
@@ -432,14 +450,17 @@ private static RevitDynamoModel InitializeCoreModel(DynamoRevitCommandData comma
432450

433451
bool isAutomationMode = CheckJournalForKey(extCommandData,JournalKeys.AutomationModeKey);
434452

435-
PreloadAsmFromRevit();
453+
// when Dynamo runs on top of revit we must load the same version of ASM as revit
454+
// so tell Dynamo core we've loaded that version.
455+
var loadedLibGVersion = PreloadAsmFromRevit();
456+
436457

437-
return RevitDynamoModel.Start(
458+
return RevitDynamoModel.Start(
438459
new RevitDynamoModel.RevitStartConfiguration()
439460
{
440461
DynamoCorePath = corePath,
441462
DynamoHostPath = dynamoRevitRoot,
442-
GeometryFactoryPath = GetGeometryFactoryPath(corePath),
463+
GeometryFactoryPath = GetGeometryFactoryPath(corePath, loadedLibGVersion),
443464
PathResolver = new RevitPathResolver(userDataFolder, commonDataFolder),
444465
Context = GetRevitContext(commandData),
445466
SchedulerThread = new RevitSchedulerThread(commandData.Application),
@@ -451,18 +472,32 @@ private static RevitDynamoModel InitializeCoreModel(DynamoRevitCommandData comma
451472
});
452473
}
453474

454-
private static void PreloadAsmFromRevit()
475+
internal static Version PreloadAsmFromRevit()
455476
{
456477
var asmLocation = AppDomain.CurrentDomain.BaseDirectory;
457478

458-
var lookup = new InstalledProductLookUp("Revit", "ASMAHL*.dll");
459-
var product = lookup.GetProductFromInstallPath(asmLocation);
479+
Version libGversion = findRevitASMVersion(asmLocation);
460480

461481
var dynCorePath = DynamoRevitApp.DynamoCorePath;
462-
var libGFolderName = string.Format("libg_{0}", product.VersionInfo.Item1);
482+
var libGFolderName = string.Format("libg_{0}_{1}_{2}", libGversion.Major, libGversion.Minor, libGversion.Build);
463483
var preloaderLocation = Path.Combine(dynCorePath, libGFolderName);
464484

465485
DynamoShapeManager.Utilities.PreloadAsmFromPath(preloaderLocation, asmLocation);
486+
return libGversion;
487+
}
488+
489+
/// <summary>
490+
/// Returns the version of ASM which is installed with Revit at the requested path.
491+
/// This version number can be used to load the appropriate libG version.
492+
/// </summary>
493+
/// <param name="asmLocation">path where asm dlls are located, this is usually the product(Revit) install path</param>
494+
/// <returns></returns>
495+
internal static Version findRevitASMVersion(string asmLocation)
496+
{
497+
var lookup = new InstalledProductLookUp("Revit", "ASMAHL*.dll");
498+
var product = lookup.GetProductFromInstallPath(asmLocation);
499+
var libGversion = new Version(product.VersionInfo.Item1, product.VersionInfo.Item2, product.VersionInfo.Item3);
500+
return libGversion;
466501
}
467502

468503
private static DynamoViewModel InitializeCoreViewModel(RevitDynamoModel revitDynamoModel)

src/DynamoRevit/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
[assembly: AssemblyTitle("DynamoRevitDS")]
99
[assembly: AssemblyCulture("")]
1010
[assembly: Guid("082cab33-cbc7-4e58-ae25-f0962f325d6e")]
11+
[assembly: InternalsVisibleTo("RevitTestServices")]

test/Libraries/RevitTestServices/RevitNodeTestBase.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
using System;
12
using System.IO;
23
using System.Reflection;
3-
4+
using Dynamo.Applications;
45
using DynamoUnits;
56

67
using NUnit.Framework;
@@ -43,7 +44,8 @@ public override void Setup()
4344

4445
protected override TestSessionConfiguration GetTestSessionConfiguration()
4546
{
46-
return new TestSessionConfiguration(Dynamo.Applications.DynamoRevitApp.DynamoCorePath);
47+
var asmLocation = AppDomain.CurrentDomain.BaseDirectory;
48+
return new TestSessionConfiguration(Dynamo.Applications.DynamoRevitApp.DynamoCorePath, DynamoRevit.findRevitASMVersion(asmLocation));
4749
}
4850

4951
private static void SetupTransactionManager()

test/Libraries/RevitTestServices/RevitSystemTestBase.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,14 @@ protected override void StartDynamo(TestSessionConfiguration testConfig)
207207
var revitTestPathResolver = new RevitTestPathResolver();
208208
revitTestPathResolver.InitializePreloadedLibraries();
209209

210+
//preload ASM and instruct dynamo to load that version of libG.
211+
var requestedLibGVersion = DynamoRevit.PreloadAsmFromRevit();
212+
210213
DynamoRevit.RevitDynamoModel = RevitDynamoModel.Start(
211214
new RevitDynamoModel.RevitStartConfiguration()
212215
{
213216
StartInTestMode = true,
214-
GeometryFactoryPath = DynamoRevit.GetGeometryFactoryPath(testConfig.DynamoCorePath),
217+
GeometryFactoryPath = DynamoRevit.GetGeometryFactoryPath(testConfig.DynamoCorePath, requestedLibGVersion),
215218
DynamoCorePath = testConfig.DynamoCorePath,
216219
PathResolver = revitTestPathResolver,
217220
Context = "Revit 2014",

test/Libraries/RevitTestServices/TestServices.dll.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
<configuration>
33
<appSettings>
44
<add key="DynamoBasePath" value=""/>
5-
<add key="RequestedLibraryVersion" value="Version223"/>
5+
<add key="RequestedLibraryVersion2" value="hostdefault"/>
66
</appSettings>
77
</configuration>

0 commit comments

Comments
 (0)