public static HoneybeeSchema.Face3D ToLadybugTools(this Face3D face3D) { if (face3D == null) { return(null); } ISegmentable3D externalEdge = face3D.GetExternalEdge3D() as ISegmentable3D; if (externalEdge == null) { throw new System.NotImplementedException(); } List <Point3D> point3Ds = externalEdge.GetPoints(); if (point3Ds == null || point3Ds.Count < 3) { return(null); } List <List <double> > boundary = ToLadybugTools(point3Ds); if (boundary == null || boundary.Count == 0) { return(null); } List <List <List <double> > > holes = new List <List <List <double> > >(); List <IClosedPlanar3D> internalEdges = face3D.GetInternalEdge3Ds(); if (internalEdges != null && internalEdges.Count > 0) { foreach (IClosedPlanar3D internalEdge_Temp in internalEdges) { ISegmentable3D internalEdge = internalEdge_Temp as ISegmentable3D; if (internalEdge == null) { throw new System.NotImplementedException(); } point3Ds = internalEdge.GetPoints(); if (point3Ds == null || point3Ds.Count < 3) { continue; } List <List <double> > hole = ToLadybugTools(point3Ds); if (hole == null || hole.Count == 0) { continue; } holes.Add(hole); } } return(new HoneybeeSchema.Face3D(boundary, holes)); }
public static HashSet <Point3D> ExternalEdgePoint3Ds(this Face3D face3D, double tolerance = Core.Tolerance.Distance) { if (face3D == null) { return(null); } Face3D face3D_Temp = new Face3D(face3D); face3D_Temp.Normalize(tolerance); ISegmentable3D externalEdge = face3D_Temp.GetExternalEdge3D() as ISegmentable3D; if (externalEdge == null) { throw new NotImplementedException(); } List <Point3D> point3Ds = externalEdge.GetPoints(); if (point3Ds == null) { return(null); } //Vector3D normal = face3D.GetPlane().Normal; //if (normal == null) // return null; //ISegmentable3D externalEdge = face3D.GetExternalEdge3D() as ISegmentable3D; //if (externalEdge == null) // throw new NotImplementedException(); //List<Point3D> point3Ds = externalEdge.GetPoints(); //if (point3Ds == null) // return null; //if (!Spatial.Query.Clockwise(point3Ds, normal, Core.Tolerance.Angle, tolerance)) // point3Ds.Reverse(); HashSet <Point3D> result = new HashSet <Point3D>(); if (point3Ds.Count == 0) { return(result); } for (int i = 0; i < point3Ds.Count; i++) { point3Ds[i].Round(tolerance); result.Add(point3Ds[i]); } return(result); }
public static Polygon3D ToSAM_Polygon3D(this CurveArray curveArray, XYZ normal = null) { List <Point3D> point3Ds = new List <Point3D>(); foreach (Curve curve in curveArray) { ISegmentable3D segmentable3D = curve.ToSAM() as ISegmentable3D; if (segmentable3D == null) { continue; } List <Point3D> point3Ds_Temp = segmentable3D.GetPoints(); if (point3Ds_Temp == null || point3Ds_Temp.Count == 0) { continue; } if (point3Ds_Temp.Count == 1) { point3Ds.Add(point3Ds_Temp[0]); continue; } point3Ds_Temp.RemoveAt(point3Ds_Temp.Count - 1); point3Ds_Temp.ForEach(x => point3Ds.Add(x)); } if (point3Ds == null || point3Ds.Count == 0) { return(null); } Polygon3D result = null; if (normal != null) { result = Spatial.Create.Polygon3D(normal.ToSAM_Vector3D(false), point3Ds); } if (result == null) { result = Spatial.Create.Polygon3D(point3Ds); } return(result); }
public static List <List <Point3D> > InternalEdgesPoint3Ds(this Face3D face3D, double tolerance = Core.Tolerance.Distance) { if (face3D == null) { return(null); } List <IClosedPlanar3D> internalEdges = face3D.GetInternalEdge3Ds(); if (internalEdges == null || internalEdges.Count == 0) { return(null); } List <List <Point3D> > result = new List <List <Point3D> >(); foreach (IClosedPlanar3D closedPlanar3D in internalEdges) { ISegmentable3D internalEdge = closedPlanar3D as ISegmentable3D; if (internalEdge == null) { throw new NotImplementedException(); } List <Point3D> point3Ds = internalEdge.GetPoints(); if (point3Ds == null || point3Ds.Count < 3) { continue; } point3Ds.ForEach(x => x.Round(tolerance)); result.Add(point3Ds); } return(result); }
public static List <Aperture> ToSAM_Apertures(this FamilyInstance familyInstance, ConvertSettings convertSettings) { if (familyInstance == null) { return(null); } List <Aperture> result = convertSettings?.GetObjects <Aperture>(familyInstance.Id); if (result != null) { return(result); } if (Core.Revit.Query.Simplified(familyInstance)) { result = Core.Revit.Query.IJSAMObjects <Aperture>(familyInstance); if (result != null) { convertSettings?.Add(familyInstance.Id, result); return(result); } } Point3D point3D_Location = Geometry.Revit.Query.LocationPoint3D(familyInstance); if (point3D_Location == null) { List <Solid> solids = Core.Revit.Query.Solids(familyInstance, new Options()); solids?.RemoveAll(x => x.Volume == 0); if (solids == null || solids.Count == 0) { return(null); } if (solids.Count > 1) { solids.Sort((x, y) => y.Volume.CompareTo(x.Volume)); } point3D_Location = solids[0].ComputeCentroid()?.ToSAM(); } if (point3D_Location == null) { return(null); } List <Face3D> face3Ds = null; PanelType panelType_Host = PanelType.Undefined; BuiltInCategory builtInCategory_Host = BuiltInCategory.INVALID; HostObject hostObject = null; if (familyInstance.Host != null) { hostObject = familyInstance.Host as HostObject; if (hostObject != null) { builtInCategory_Host = (BuiltInCategory)hostObject.Category.Id.IntegerValue; } } //Method 1 of extracting Geometry if (face3Ds == null || face3Ds.Count == 0) { Vector3D axisX = null; Vector3D normal = null; Vector3D axisY = null; if (builtInCategory_Host == BuiltInCategory.OST_Roofs) { axisX = familyInstance.HandOrientation.ToSAM_Vector3D(false); axisY = familyInstance.FacingOrientation.ToSAM_Vector3D(false); normal = Geometry.Spatial.Query.AxisY(axisY, axisX); } else { axisX = familyInstance.HandOrientation.ToSAM_Vector3D(false); normal = familyInstance.FacingOrientation.ToSAM_Vector3D(false); axisY = Geometry.Spatial.Query.AxisY(normal, axisX); } Geometry.Spatial.Plane plane = Geometry.Spatial.Create.Plane(point3D_Location, axisX, axisY); if (!plane.Normal.SameHalf(normal)) { plane.FlipZ(false); } List <Shell> shells = Geometry.Revit.Convert.ToSAM_Geometries <Shell>(familyInstance); if (shells == null || shells.Count == 0) { return(null); } List <Point2D> point2Ds = new List <Point2D>(); foreach (Shell shell in shells) { List <Face3D> face3Ds_Shell = shell?.Face3Ds; if (face3Ds_Shell == null || face3Ds_Shell.Count == 0) { continue; } foreach (Face3D face3D_Temp in face3Ds_Shell) { ISegmentable3D segmentable3D = face3D_Temp.GetExternalEdge3D() as ISegmentable3D; if (segmentable3D == null) { continue; } segmentable3D?.GetPoints()?.ForEach(x => point2Ds.Add(plane.Convert(x))); } } Face3D face3D = new Face3D(plane, Geometry.Planar.Create.Rectangle2D(point2Ds)); if (face3D != null && face3D.IsValid() && face3D.GetArea() > Core.Tolerance.MacroDistance) { face3Ds = new List <Face3D>() { face3D }; } } //Method 2 of extracting Geometry if (hostObject != null) { builtInCategory_Host = (BuiltInCategory)hostObject.Category.Id.IntegerValue; Geometry.Spatial.Plane plane_Host = null; if (hostObject is CurtainSystem && familyInstance is Autodesk.Revit.DB.Panel) { Autodesk.Revit.DB.Panel panel = (Autodesk.Revit.DB.Panel)familyInstance; ElementId uGridLineElementId = null; ElementId vGridLineElementId = null; panel.GetRefGridLines(ref uGridLineElementId, ref vGridLineElementId); CurtainSystem curtainSystem = (CurtainSystem)hostObject; List <Polygon3D> polygon3Ds = curtainSystem.CurtainCell(uGridLineElementId, vGridLineElementId)?.Polygon3Ds(); if (polygon3Ds != null && polygon3Ds.Count != 0) { polygon3Ds.Sort((x, y) => y.GetArea().CompareTo(x.GetArea())); plane_Host = polygon3Ds[0].GetPlane(); } } else { List <Face3D> face3Ds_Temp = hostObject.Profiles(); if (face3Ds_Temp != null && face3Ds_Temp.Count != 0) { plane_Host = face3Ds_Temp.Closest(point3D_Location)?.GetPlane(); } } if (plane_Host != null) { face3Ds = face3Ds?.ConvertAll(x => plane_Host.Project(x)); point3D_Location = plane_Host.Project(point3D_Location); } HostObjAttributes hostObjAttributes = familyInstance.Document.GetElement(hostObject.GetTypeId()) as HostObjAttributes; if (hostObjAttributes != null) { panelType_Host = hostObjAttributes.PanelType(); } if (panelType_Host == PanelType.Undefined) { panelType_Host = hostObject.PanelType(); } List <Face3D> face3Ds_Profiles = hostObject.Profiles(familyInstance.Id); face3Ds_Profiles?.RemoveAll(x => x == null || !x.IsValid()); if (face3Ds_Profiles != null && face3Ds_Profiles.Count > 0) { if (face3Ds == null || (face3Ds != null && face3Ds_Profiles.ConvertAll(x => x.GetArea()).Sum() <= face3Ds.ConvertAll(x => x.GetArea()).Sum())) { face3Ds = face3Ds_Profiles; } } } ApertureConstruction apertureConstruction = ToSAM_ApertureConstruction(familyInstance, convertSettings); if (apertureConstruction == null && panelType_Host != PanelType.Undefined) { apertureConstruction = Analytical.Query.DefaultApertureConstruction(panelType_Host, familyInstance.ApertureType()); //Default Aperture Construction } if (face3Ds == null || face3Ds.Count == 0) { return(result); } //TODO: Working on SAM Families (requested by Michal) string parameterName_Height = Core.Revit.Query.Name(ActiveSetting.Setting, typeof(Aperture), typeof(FamilyInstance), "GetHeight"); string parameterName_Width = Core.Revit.Query.Name(ActiveSetting.Setting, typeof(Aperture), typeof(FamilyInstance), "GetWidth"); if (!string.IsNullOrWhiteSpace(parameterName_Height) && !string.IsNullOrWhiteSpace(parameterName_Width)) { Parameter parameter_Height = familyInstance.LookupParameter(parameterName_Height); Parameter parameter_Width = familyInstance.LookupParameter(parameterName_Width); if (parameter_Height != null && parameter_Width != null && parameter_Height.HasValue && parameter_Width.HasValue && parameter_Height.StorageType == StorageType.Double && parameter_Width.StorageType == StorageType.Double) { #if Revit2017 || Revit2018 || Revit2019 || Revit2020 double height = UnitUtils.ConvertFromInternalUnits(parameter_Height.AsDouble(), DisplayUnitType.DUT_METERS); double width = UnitUtils.ConvertFromInternalUnits(parameter_Width.AsDouble(), DisplayUnitType.DUT_METERS); #else double height = UnitUtils.ConvertFromInternalUnits(parameter_Height.AsDouble(), UnitTypeId.Meters); double width = UnitUtils.ConvertFromInternalUnits(parameter_Width.AsDouble(), UnitTypeId.Meters); #endif } } result = new List <Aperture>(); foreach (Face3D face3D_Temp in face3Ds) { Aperture aperture = Analytical.Create.Aperture(apertureConstruction, face3D_Temp); if (aperture == null) { continue; } aperture.UpdateParameterSets(familyInstance, ActiveSetting.Setting.GetValue <Core.TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap)); result.Add(aperture); } convertSettings?.Add(familyInstance.Id, result); return(result); }
public static T Find <T>(this IEnumerable <Element> elements, ISegmentable3D segmentable3D, double min = Tolerance.Distance, double max = Tolerance.MacroDistance) where T : Element { if (elements == null || segmentable3D == null) { return(null); } List <Tuple <T, ISAMGeometry3D, double> > tuples = new List <Tuple <T, ISAMGeometry3D, double> >(); foreach (Element element in elements) { T t = element as T; if (t == null) { continue; } ISAMGeometry3D sAMGeometry3D = element?.Location(); if (sAMGeometry3D == null) { continue; } if (sAMGeometry3D is Point3D) { Point3D point3D_Temp = (Point3D)sAMGeometry3D; double distance = segmentable3D.Distance(point3D_Temp); if (distance <= min) { return(t); } if (distance > max) { continue; } tuples.Add(new Tuple <T, ISAMGeometry3D, double>(t, point3D_Temp, distance)); } else if (sAMGeometry3D is ISegmentable3D) { ISegmentable3D segmentable3D_Temp = (ISegmentable3D)sAMGeometry3D; double distance = segmentable3D.Distance(segmentable3D_Temp, min); if (distance > max) { continue; } List <Point3D> point3Ds_Temp = segmentable3D_Temp.GetPoints(); List <Point3D> point3Ds = segmentable3D.GetPoints(); List <double> distances_Temp = point3Ds_Temp.ConvertAll(x => segmentable3D.Distance(x)); List <double> distances = point3Ds.ConvertAll(x => segmentable3D.Distance(x)); if (distance <= min && distances_Temp.TrueForAll(x => x < min) && distances.TrueForAll(x => x < min)) { return(t); } int count = (distances_Temp.Count + distances.Count) - (distances_Temp.FindAll(x => x < min).Count + distances.FindAll(x => x < min).Count); tuples.Add(new Tuple <T, ISAMGeometry3D, double>(t, segmentable3D, count)); } } if (tuples == null || tuples.Count == 0) { return(null); } if (tuples.Count == 1) { return(tuples[0].Item1); } tuples.Sort((x, y) => x.Item3.CompareTo(y.Item3)); return(tuples.First().Item1); }
public static TBD.Perimeter ToTBD(this Face3D face3D, TBD.RoomSurface roomSurface = null) { if (face3D == null) { return(null); } IClosedPlanar3D externalEdge3D = face3D.GetExternalEdge3D(); if (externalEdge3D == null) { return(null); } ISegmentable3D segmentable3D = externalEdge3D as ISegmentable3D; if (segmentable3D == null) { throw new System.NotImplementedException(); } TBD.Perimeter result = roomSurface?.CreatePerimeter(); if (result == null) { result = new TBD.Perimeter(); } TBD.Polygon polygon = result.CreateFace(); List <Point3D> point3Ds = segmentable3D.GetPoints(); if (point3Ds != null) { foreach (Point3D point3D in point3Ds) { if (point3D == null) { continue; } polygon.AddCoordinate(System.Convert.ToSingle(point3D.X), System.Convert.ToSingle(point3D.Y), System.Convert.ToSingle(point3D.Z)); } } List <IClosedPlanar3D> internalEdge3Ds = face3D.GetInternalEdge3Ds(); if (internalEdge3Ds != null && internalEdge3Ds.Count != 0) { foreach (IClosedPlanar3D closedPlanar3D in internalEdge3Ds) { if (closedPlanar3D == null) { continue; } segmentable3D = closedPlanar3D as ISegmentable3D; if (segmentable3D == null) { throw new System.NotImplementedException(); } polygon = result.AddHole(); point3Ds = segmentable3D.GetPoints(); if (point3Ds != null) { foreach (Point3D point3D in point3Ds) { if (point3D == null) { continue; } polygon.AddCoordinate(System.Convert.ToSingle(point3D.X), System.Convert.ToSingle(point3D.Y), System.Convert.ToSingle(point3D.Z)); } } } } return(result); }