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 6 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,23 @@ out List<string> notes
status: ApplicationObject.State.Created,
logItem: $"Attached as hosted element to {host.UniqueId}"
);

double area = GetAreaOfHostedElement(element as DB.FamilyInstance, host as DB.Wall);
#if REVIT2020
double area_transformed = UnitUtils.ConvertFromInternalUnits(area, DisplayUnitType.DUT_SQUARE_METERS);
#else
double area_transformed = UnitUtils.ConvertFromInternalUnits(area, UnitTypeId.SquareMeters);
#endif
var paramObject = obj["parameters"];
if( paramObject != null )
{
Base parameters = (Base)paramObject;
if (parameters != null)
{
Objects.BuiltElements.Revit.Parameter hostedAreaParameter = new Parameter("Cutout Area", area_transformed, "m²");
parameters["Cutout Area"] = hostedAreaParameter;
}
}
convertedHostedElements.Add(obj);
ConvertedObjects.Add(obj.applicationId);
}
Expand Down Expand Up @@ -1108,6 +1126,23 @@ 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_sqft = IFC.ExporterIFCUtils.ComputeAreaOfCurveLoops(loops);
return area_sqft;
}


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