-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dui3 177 receive levels in Revit (#3553)
* Auto stash before checking out "origin/dui3/alpha" * Fix Rhino lock * address pr comments * add level receive (and top level send) * fix merge * fix rebase operation --------- Co-authored-by: Connor Ivy <[email protected]> Co-authored-by: Adam Hathcock <[email protected]>
- Loading branch information
1 parent
7451d8e
commit 5fddfd9
Showing
5 changed files
with
114 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitRootToHostConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Speckle.Converters.Common; | ||
using Speckle.Converters.Common.Objects; | ||
using Speckle.Core.Models; | ||
|
||
namespace Speckle.Converters.RevitShared; | ||
|
||
public class RevitRootToHostConverter : IRootToHostConverter | ||
{ | ||
private readonly IConverterResolver<IToHostTopLevelConverter> _converterResolver; | ||
|
||
public RevitRootToHostConverter(IConverterResolver<IToHostTopLevelConverter> converterResolver) | ||
{ | ||
_converterResolver = converterResolver; | ||
} | ||
|
||
public object Convert(Base target) | ||
{ | ||
var objectConverter = _converterResolver.GetConversionForType(target.GetType()); | ||
|
||
if (objectConverter == null) | ||
{ | ||
throw new SpeckleConversionException($"No conversion found for {target.GetType().Name}"); | ||
} | ||
|
||
return objectConverter.Convert(target) | ||
?? throw new SpeckleConversionException($"Conversion of object with type {target.GetType()} returned null"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...ters/Revit/Speckle.Converters.RevitShared/ToHost/TopLevel/LevelToHostTopLevelConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using Speckle.Converters.Common; | ||
using Speckle.Converters.RevitShared.Helpers; | ||
using Speckle.Converters.RevitShared.ToSpeckle; | ||
using Speckle.Converters.RevitShared.Services; | ||
|
||
namespace Speckle.Converters.RevitShared.ToHost.ToLevel; | ||
|
||
[NameAndRankValue(nameof(SOBE.Level), 0)] | ||
public class LevelToHostTopLevelConverter : BaseTopLevelConverterToHost<SOBE.Level, DB.Level> | ||
{ | ||
private readonly IRevitConversionContextStack _contextStack; | ||
private readonly ScalingServiceToHost _scalingService; | ||
|
||
public LevelToHostTopLevelConverter(IRevitConversionContextStack contextStack, ScalingServiceToHost scalingService) | ||
{ | ||
_contextStack = contextStack; | ||
_scalingService = scalingService; | ||
} | ||
|
||
public override DB.Level Convert(SOBE.Level target) | ||
{ | ||
using var documentLevelCollector = new DB.FilteredElementCollector(_contextStack.Current.Document); | ||
var docLevels = documentLevelCollector.OfClass(typeof(DB.Level)).ToElements().Cast<DB.Level>(); | ||
|
||
// POC : I'm not really understanding the linked use case for this. Do we want to bring this over? | ||
|
||
//bool elevationMatch = true; | ||
////level by name component | ||
//if (target is RevitLevel speckleRevitLevel && speckleRevitLevel.referenceOnly) | ||
//{ | ||
// //see: https://speckle.community/t/revit-connector-levels-and-spaces/2824/5 | ||
// elevationMatch = false; | ||
// if (GetExistingLevelByName(docLevels, target.name) is DB.Level existingLevelWithSameName) | ||
// { | ||
// return existingLevelWithSameName; | ||
// } | ||
//} | ||
|
||
DB.Level revitLevel; | ||
var targetElevation = _scalingService.ScaleToNative(target.elevation, target.units); | ||
|
||
if (GetExistingLevelByElevation(docLevels, targetElevation) is DB.Level existingLevel) | ||
{ | ||
revitLevel = existingLevel; | ||
} | ||
else | ||
{ | ||
revitLevel = DB.Level.Create(_contextStack.Current.Document, targetElevation); | ||
revitLevel.Name = target.name; | ||
|
||
if (target is SOBR.RevitLevel rl && rl.createView) | ||
{ | ||
using var viewPlan = CreateViewPlan(target.name, revitLevel.Id); | ||
} | ||
} | ||
|
||
return revitLevel; | ||
} | ||
|
||
private static DB.Level GetExistingLevelByElevation(IEnumerable<DB.Level> docLevels, double elevation) | ||
{ | ||
return docLevels.FirstOrDefault(l => Math.Abs(l.Elevation - elevation) < RevitConversionContextStack.TOLERANCE); | ||
} | ||
|
||
private DB.ViewPlan CreateViewPlan(string name, DB.ElementId levelId) | ||
{ | ||
using var collector = new DB.FilteredElementCollector(_contextStack.Current.Document); | ||
var vt = collector | ||
.OfClass(typeof(DB.ViewFamilyType)) | ||
.First(el => ((DB.ViewFamilyType)el).ViewFamily == DB.ViewFamily.FloorPlan); | ||
|
||
var view = DB.ViewPlan.Create(_contextStack.Current.Document, vt.Id, levelId); | ||
view.Name = name; | ||
|
||
return view; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters