/// <summary> /// /// </summary> /// <param name="curtainGridLine"></param> /// <returns></returns> public static References GetReference(Element curtainGridLine) { if (curtainGridLine == null) { throw new Exception("Curtain Grid Line cannot be null."); } if (!(curtainGridLine.InternalElement is Autodesk.Revit.DB.CurtainGridLine cgl)) { throw new Exception("Input curtainGridLine must be of type CurtainGridLine."); } var opt = new Autodesk.Revit.DB.Options { ComputeReferences = true, IncludeNonVisibleObjects = true }; var geomElement = cgl.get_Geometry(opt); foreach (var go in geomElement) { if (!(go is Autodesk.Revit.DB.Line l)) { continue; } return(new References(l.Reference)); } throw new Exception("Could not find a Line Reference."); }
private static List <Autodesk.Revit.DB.XYZ> GetGeometryPoints(Autodesk.Revit.DB.Element e) { var pts = new List <Autodesk.Revit.DB.XYZ>(); using (var opt = new Autodesk.Revit.DB.Options()) { opt.IncludeNonVisibleObjects = true; using (var geom = e.get_Geometry(opt)) { ExtractPtsRecursively(geom, ref pts); } } return(pts); }
public static Dictionary <string, object> GetFaces(Element wall) { if (wall == null) { throw new ArgumentException(nameof(wall)); } if (!(wall.InternalElement is Autodesk.Revit.DB.Wall w)) { throw new Exception("Element is not a Wall."); } var opt = new Autodesk.Revit.DB.Options { ComputeReferences = true, IncludeNonVisibleObjects = true }; var faces = new List <Surface>(); var references = new List <References>(); var geomElement = w.get_Geometry(opt); foreach (var go in geomElement) { if (!(go is Autodesk.Revit.DB.Solid s) || s.Faces.Size == 0) { continue; } var face = s.Faces.get_Item(0); faces.AddRange(face.ToProtoType()); references.Add(new References(face.Reference)); } return(new Dictionary <string, object> { { "Faces", faces }, { "References", references } }); }
public static Dictionary <string, object> PointsOnSurface( Element room, [DefaultArgument("Selection.Select.GetNull()")] List <Element> glazingMaterials, string boundaryLocation = "Center") { if (room == null) { throw new ArgumentNullException(nameof(room)); } var materialIds = new List <Autodesk.Revit.DB.ElementId>(); if (glazingMaterials != null && glazingMaterials.Any()) { materialIds = glazingMaterials.Select(x => x.InternalElement.Id).ToList(); } var bLoc = (Autodesk.Revit.DB.SpatialElementBoundaryLocation)Enum.Parse(typeof(Autodesk.Revit.DB.SpatialElementBoundaryLocation), boundaryLocation); var bOptions = new Autodesk.Revit.DB.SpatialElementBoundaryOptions { SpatialElementBoundaryLocation = bLoc }; var doc = DocumentManager.Instance.CurrentDBDocument; var tolerance = doc.Application.ShortCurveTolerance; var rm = (Autodesk.Revit.DB.SpatialElement)room.InternalElement; var calculator = new Autodesk.Revit.DB.SpatialElementGeometryCalculator(doc, bOptions); var result = calculator.CalculateSpatialElementGeometry(rm); var geo = result.GetGeometry(); var bb = geo.GetBoundingBox(); var height = bb.Max.Z - bb.Min.Z; //var units = doc.GetUnits().GetFormatOptions(Autodesk.Revit.DB.UnitType.UT_Length); //var convertedHeight = Autodesk.Revit.DB.UnitUtils.ConvertFromInternalUnits(height, units.DisplayUnits); var boundaryCurves = rm.GetBoundarySegments(bOptions).First().Select(x => x.GetCurve()).ToList(); var glazingPoints = new List <List <List <Point> > >(); var glazingRatios = new List <double>(); for (var j = 1; j < geo.Faces.Size; j++) // skip 0 as that's the Floor. { var face = geo.Faces.get_Item(j); var bottomEdge = face.GetEdgesAsCurveLoops().First().First(); // first loop is outer boundary, first curve is bottom edge var index = boundaryCurves.FindIndex(x => x.OverlapsWith(bottomEdge)); if (index == -1) { continue; // could be inner face/roof } var gPoints = new List <List <Point> >(); var gAreas = new List <double>(); if (!(face is Autodesk.Revit.DB.PlanarFace)) { glazingPoints[index] = gPoints; continue; // skip non-planar faces } var boundaryFaces = result.GetBoundaryFaceInfo(face); foreach (var bFace in boundaryFaces) { var bElement = doc.GetElement(bFace.SpatialBoundaryElement.HostElementId); if (bElement is Autodesk.Revit.DB.Wall wall) { if (wall.WallType.Kind == Autodesk.Revit.DB.WallKind.Curtain) { var cGrid = wall.CurtainGrid; var panels = cGrid.GetPanelIds().Select(x => doc.GetElement(x)); foreach (var panel in panels) { var mat = panel.GetMaterialIds(false); if (!materialIds.Any() || !materialIds.Intersect(mat).Any()) { continue; } var winPts = new List <Autodesk.Revit.DB.XYZ>(); using (var opt = new Autodesk.Revit.DB.Options()) { opt.IncludeNonVisibleObjects = true; using (var geom = panel.get_Geometry(opt)) { ExtractPtsRecursively(geom, ref winPts); } } var onSurface = new HashSet <Autodesk.Revit.DB.XYZ>(); var onSurfaceUvs = new HashSet <Autodesk.Revit.DB.UV>(); foreach (var pt in winPts) { var intResult = face.Project(pt); if (intResult == null) { continue; } if (onSurface.Add(intResult.XYZPoint)) { onSurfaceUvs.Add(intResult.UVPoint.Negate()); } } if (GetHull(onSurface.ToList(), onSurfaceUvs.ToList(), tolerance, out var hPts, out var hUvs)) { var outerEdges = face.GetEdgesAsCurveLoops().First(); foreach (var edge in outerEdges) { for (var i = 0; i < hPts.Count; i++) { var pt = hPts[i]; if (edge.Distance(pt) >= 0.01) { continue; } var direction = (edge.GetEndPoint(1) - edge.GetEndPoint(0)).Normalize(); var perpendicular = face.ComputeNormal(new Autodesk.Revit.DB.UV(0.5, 0.5)).CrossProduct(direction); var offset = 0.1 * perpendicular; var offsetPt = pt + offset; hPts[i] = offsetPt; } } gAreas.Add(PolygonArea(hUvs)); gPoints.Add(hPts.Select(x => x.ToPoint()).ToList()); } } } var inserts = wall.FindInserts(true, false, true, true).Select(x => doc.GetElement(x)); foreach (var insert in inserts) { if (insert.Category.Id.IntegerValue == Autodesk.Revit.DB.BuiltInCategory.OST_Windows.GetHashCode()) { // (Konrad) We have a Window. var winPts = new List <Autodesk.Revit.DB.XYZ>(); using (var opt = new Autodesk.Revit.DB.Options()) { opt.IncludeNonVisibleObjects = true; using (var geom = insert.get_Geometry(opt)) { ExtractPtsRecursively(geom, ref winPts); } } var onSurface = new HashSet <Autodesk.Revit.DB.XYZ>(); var onSurfaceUvs = new HashSet <Autodesk.Revit.DB.UV>(); foreach (var pt in winPts) { var intResult = face.Project(pt); if (intResult == null) { continue; } if (onSurface.Add(intResult.XYZPoint)) { onSurfaceUvs.Add(intResult.UVPoint.Negate()); } } if (GetHull(onSurface.ToList(), onSurfaceUvs.ToList(), tolerance, out var hPts, out var hUvs)) { var winArea = GetWindowArea(insert); var hullArea = PolygonArea(hUvs); if (hullArea > winArea * 0.5) { var outerEdges = face.GetEdgesAsCurveLoops().First(); foreach (var edge in outerEdges) { for (var i = 0; i < hPts.Count; i++) { var pt = hPts[i]; if (edge.Distance(pt) >= 0.01) { continue; } var direction = (edge.GetEndPoint(1) - edge.GetEndPoint(0)).Normalize(); var perpendicular = face.ComputeNormal(new Autodesk.Revit.DB.UV(0.5, 0.5)).CrossProduct(direction); var offset = 0.03 * perpendicular; var offsetPt = pt + offset; hPts[i] = offsetPt; } } gAreas.Add(PolygonArea(hUvs)); gPoints.Add(hPts.Select(x => x.ToPoint()).ToList()); } } } } } else if (bElement is Autodesk.Revit.DB.RoofBase roof) { var inserts = roof.FindInserts(true, false, true, true).Select(x => doc.GetElement(x)); foreach (var insert in inserts) { if (insert.Category.Id.IntegerValue == Autodesk.Revit.DB.BuiltInCategory.OST_Windows.GetHashCode()) { // (Konrad) We have a Window. var winPts = new List <Autodesk.Revit.DB.XYZ>(); using (var opt = new Autodesk.Revit.DB.Options()) { opt.IncludeNonVisibleObjects = true; using (var geom = insert.get_Geometry(opt)) { ExtractPtsRecursively(geom, ref winPts); } } var onSurface = new HashSet <Autodesk.Revit.DB.XYZ>(); var onSurfaceUvs = new HashSet <Autodesk.Revit.DB.UV>(); foreach (var pt in winPts) { var intResult = face.Project(pt); if (intResult == null) { continue; } if (onSurface.Add(intResult.XYZPoint)) { onSurfaceUvs.Add(intResult.UVPoint.Negate()); } } if (GetHull(onSurface.ToList(), onSurfaceUvs.ToList(), tolerance, out var hPts, out var hUvs)) { var winArea = GetWindowArea(insert); var hullArea = PolygonArea(hUvs); if (hullArea > winArea * 0.25) { gAreas.Add(hullArea); gPoints.Add(hPts.Select(x => x.ToPoint()).ToList()); } } } } } } var curve = face.GetEdgesAsCurveLoops().FirstOrDefault()?.FirstOrDefault(); if (curve == null) { continue; } var faceArea = curve.Length * height; glazingPoints[index] = gPoints; glazingRatios[index] = gAreas.Sum() / faceArea; } return(new Dictionary <string, object> { { "GlazingPoints", glazingPoints }, { "GlazingRatios", glazingRatios } }); }