Skip to content

Commit

Permalink
cherry pick jeremytammik/RevitLookup#187 - GetBoundarySegments method…
Browse files Browse the repository at this point in the history
… of spatial elements support added
  • Loading branch information
NeVeSpl committed Nov 28, 2023
1 parent 1e089d5 commit 4a9ff14
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Collections.Generic;
using System.Linq.Expressions;
using Autodesk.Revit.DB;

// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md

namespace RevitDBExplorer.Domain.DataModel.MemberAccessors
{
internal class SpatialElement_GetBoundarySegments : MemberAccessorByType<SpatialElement>, ICanCreateMemberAccessor
{
public IEnumerable<LambdaExpression> GetHandledMembers() { yield return (SpatialElement x) => x.GetBoundarySegments(null); }


protected override bool CanBeSnoooped(Document document, SpatialElement value) => true;

protected override string GetLabel(Document document, SpatialElement value)
{
return "[[BoundarySegment]]";
}

protected override IEnumerable<SnoopableObject> Snooop(Document document, SpatialElement element)
{
var options = new[]
{
new SpatialElementBoundaryOptions() { SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Center, StoreFreeBoundaryFaces = true },
new SpatialElementBoundaryOptions() { SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.CoreBoundary, StoreFreeBoundaryFaces = true },
new SpatialElementBoundaryOptions() { SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Finish, StoreFreeBoundaryFaces = true },
new SpatialElementBoundaryOptions() { SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.CoreCenter, StoreFreeBoundaryFaces = true },
new SpatialElementBoundaryOptions() { SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Center, StoreFreeBoundaryFaces = false },
new SpatialElementBoundaryOptions() { SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.CoreBoundary, StoreFreeBoundaryFaces = false },
new SpatialElementBoundaryOptions() { SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Finish, StoreFreeBoundaryFaces = false },
new SpatialElementBoundaryOptions() { SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.CoreCenter, StoreFreeBoundaryFaces = false },
};

foreach (var option in options)
{
yield return SnoopableObject.CreateKeyValuePair(document, option, element.GetBoundarySegments(option), "options");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ internal static class ValueContainerFactory
new RevitApiEventArgsHandler(),
new WorksetIdHandler(),
new FailureDefinitionIdHandler(),
new SpatialElementBoundaryOptionsHandler(),
new BoundarySegmentHandler(),

// generic
new ElementHandler(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Autodesk.Revit.DB;
using RevitDBExplorer.Domain.DataModel.ValueContainers.Base;

// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md

namespace RevitDBExplorer.Domain.DataModel.ValueContainers
{
internal class BoundarySegmentHandler : TypeHandler<BoundarySegment>
{
protected override bool CanBeSnoooped(SnoopableContext context, BoundarySegment boundarySegment) => boundarySegment is not null;

protected override string ToLabel(SnoopableContext context, BoundarySegment boundarySegment)
{
return $"ID: {boundarySegment.ElementId}, {boundarySegment.GetCurve()?.Length} ft"; ;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Autodesk.Revit.DB;
using RevitDBExplorer.Domain.DataModel.ValueContainers.Base;

// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md

namespace RevitDBExplorer.Domain.DataModel.ValueContainers
{
internal class SpatialElementBoundaryOptionsHandler : TypeHandler<SpatialElementBoundaryOptions>
{
protected override bool CanBeSnoooped(SnoopableContext context, SpatialElementBoundaryOptions value) => true;
protected override string ToLabel(SnoopableContext context, SpatialElementBoundaryOptions value)
{
if (value.StoreFreeBoundaryFaces == true)
{
return $"{value.SpatialElementBoundaryLocation}, store free boundary faces";
}

return $"{value.SpatialElementBoundaryLocation}";
}
}
}

0 comments on commit 4a9ff14

Please sign in to comment.