Skip to content
This repository was archived by the owner on May 12, 2026. It is now read-only.

Commit 7451d8e

Browse files
connorivyConnor Ivy
andauthored
Dui3 178 gridlines (#3554)
add gridline conversion Co-authored-by: Connor Ivy <connor@speckle.systems>
1 parent a2954b1 commit 7451d8e

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

‎DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Speckle.Converters.RevitShared.projitems‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<Compile Include="$(MSBuildThisFileDirectory)ToHost\Raw\Geometry\PolylineConverterToHost.cs" />
3737
<Compile Include="$(MSBuildThisFileDirectory)ToHost\Raw\Geometry\VectorConverterToHost.cs" />
3838
<Compile Include="$(MSBuildThisFileDirectory)ToHost\TopLevel\BaseTopLevelConverterToHost.cs" />
39+
<Compile Include="$(MSBuildThisFileDirectory)ToHost\TopLevel\GridlineToHostTopLevelConverter.cs" />
3940
<Compile Include="$(MSBuildThisFileDirectory)ToHost\TopLevel\ModelCurveToSpeckleTopLevelConverter.cs" />
4041
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Raw\BeamConversionToSpeckle.cs" />
4142
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Raw\BoundarySegmentConversionToSpeckle.cs" />
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using Objects;
2+
using Speckle.Converters.Common;
3+
using Speckle.Converters.Common.Objects;
4+
using Speckle.Converters.RevitShared.Helpers;
5+
using Speckle.Converters.RevitShared.ToSpeckle;
6+
7+
namespace Speckle.Converters.RevitShared.ToHost.TopLevel;
8+
9+
[NameAndRankValue(nameof(SOBE.GridLine), 0)]
10+
internal class GridlineToHostTopLevelConverter : BaseTopLevelConverterToHost<SOBE.GridLine, DB.Grid>
11+
{
12+
private readonly ITypedConverter<ICurve, DB.CurveArray> _curveConverter;
13+
private readonly IRevitConversionContextStack _contextStack;
14+
15+
public GridlineToHostTopLevelConverter(
16+
ITypedConverter<ICurve, DB.CurveArray> curveConverter,
17+
IRevitConversionContextStack contextStack
18+
)
19+
{
20+
_curveConverter = curveConverter;
21+
_contextStack = contextStack;
22+
}
23+
24+
public override DB.Grid Convert(SOBE.GridLine target)
25+
{
26+
DB.Curve curve = _curveConverter.Convert(target.baseLine).get_Item(0);
27+
28+
using DB.Grid revitGrid = curve switch
29+
{
30+
DB.Arc arc => DB.Grid.Create(_contextStack.Current.Document, arc),
31+
DB.Line line => DB.Grid.Create(_contextStack.Current.Document, line),
32+
_ => throw new SpeckleConversionException($"Grid line curve is of type {curve.GetType()} which is not supported")
33+
};
34+
35+
if (!string.IsNullOrEmpty(target.label) && !GridNameIsTaken(target.label))
36+
{
37+
revitGrid.Name = target.label;
38+
}
39+
40+
return revitGrid;
41+
}
42+
43+
private bool GridNameIsTaken(string gridName)
44+
{
45+
using var collector = new DB.FilteredElementCollector(_contextStack.Current.Document);
46+
47+
IEnumerable<string> gridNames = collector
48+
.WhereElementIsNotElementType()
49+
.OfClass(typeof(DB.Grid))
50+
.ToElements()
51+
.Cast<DB.Grid>()
52+
.Select(grid => grid.Name);
53+
54+
return gridNames.Contains(gridName);
55+
}
56+
}

0 commit comments

Comments
 (0)