Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hosted element area to parameters in Revit. #3539

Open
wants to merge 12 commits into
base: dev
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

<ItemGroup>
<PackageReference Include="ModPlus.Revit.API.2020" Version="1.0.0" ExcludeAssets="runtime" />
<PackageReference Include="Nice3point.Revit.Api.RevitAPIIFC" Version="2020.2.60" ExcludeAssets="runtime"/>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

<ItemGroup>
<PackageReference Include="ModPlus.Revit.API.2021" Version="1.0.0" ExcludeAssets="runtime" />
<PackageReference Include="Nice3point.Revit.Api.RevitAPIIFC" Version="2021.1.50" ExcludeAssets="runtime" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Speckle.Revit.API" Version="2022.0.2.1" />
<PackageReference Include="Nice3point.Revit.Api.RevitAPIIFC" Version="2022.1.21" />
<PackageReference Include="Speckle.Revit.API" Version="2022.0.2.1" ExcludeAssets="runtime" />
</ItemGroup>

<Target Name="CopyTemplatesToKitfolder" AfterTargets="CopyToKitFolder" Condition="'$(IsDesktopBuild)' == true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Speckle.Revit.API" Version="2023.0.0" />
<PackageReference Include="Nice3point.Revit.Api.RevitAPIIFC" Version="2023.1.1" />
<PackageReference Include="Speckle.Revit.API" Version="2023.0.0" ExcludeAssets="runtime" />
</ItemGroup>

<Target Name="CopyTemplatesToKitfolder" AfterTargets="CopyToKitFolder" Condition="'$(IsDesktopBuild)' == true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<Import Project="..\ConverterRevitShared\ConverterRevitShared.projitems" Label="Shared" />

<ItemGroup>
<PackageReference Include="Nice3point.Revit.Api.RevitAPIIFC" Version="2024.2.0" ExcludeAssets="runtime" />
<PackageReference Include="Speckle.Revit.API" Version="2024.0.0" IncludeAssets="compile;build" PrivateAssets="all" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<Import Project="..\ConverterRevitShared\ConverterRevitShared.projitems" Label="Shared" />

<ItemGroup>
<PackageReference Include="Nice3point.Revit.Api.RevitAPIIFC" Version="2025.2.0" ExcludeAssets="runtime" />
<PackageReference Include="Speckle.Revit.API" Version="2025.0.0" IncludeAssets="compile;build" PrivateAssets="all" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Speckle.Core.Models;
using Speckle.Core.Models.Extensions;
using DB = Autodesk.Revit.DB;
using IFC = Autodesk.Revit.DB.IFC;
using Level = Objects.BuiltElements.Level;
using Line = Objects.Geometry.Line;
using Parameter = Objects.BuiltElements.Revit.Parameter;
Expand Down Expand Up @@ -144,6 +145,31 @@ out List<string> notes
status: ApplicationObject.State.Created,
logItem: $"Attached as hosted element to {host.UniqueId}"
);

if (host is DB.Wall wall)
{
double area = GetAreaOfHostedElement(element as DB.FamilyInstance, wall);
#if REVIT2020
double areaTransformed = UnitUtils.ConvertFromInternalUnits(area, DisplayUnitType.DUT_SQUARE_METERS);
#else
double areaTransformed = UnitUtils.ConvertFromInternalUnits(area, UnitTypeId.SquareMeters);
#endif
var paramObject = obj["parameters"];
if (paramObject != null)
{
Base parameters = (Base)paramObject;
if (parameters != null)
{
var hostedAreaParameter = new Parameter(
"Cutout Area",
areaTransformed,
Speckle.Core.Kits.Units.Meters
); // POC: it's always in meters, even if project units are something else
parameters["Cutout Area"] = hostedAreaParameter;
}
}
}

convertedHostedElements.Add(obj);
ConvertedObjects.Add(obj.applicationId);
}
Expand Down Expand Up @@ -1108,6 +1134,27 @@ public WallLocationLine GetWallLocationLine(LocationLine location)
}
}

/// <summary>
/// Computes the area of an object in a Host element
/// </summary>
/// <param name="hostedElement"></param>
/// <param name="host"></param>
/// <returns></returns>
public double GetAreaOfHostedElement(DB.FamilyInstance hostedElement, Wall host)
{
XYZ basisY = XYZ.BasisY;
CurveLoop curveLoop = IFC.ExporterIFCUtils.GetInstanceCutoutFromWall(
host.Document,
host,
hostedElement,
out basisY
);
IList<CurveLoop> loops = new List<CurveLoop>(1);
loops.Add(curveLoop);
double area = IFC.ExporterIFCUtils.ComputeAreaOfCurveLoops(loops);
return area;
}

#region materials
public RenderMaterial? GetElementRenderMaterial(DB.Element? element)
{
Expand Down