@@ -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 )
0 commit comments