public static Edge ToTopologic(this ICurve3D curve3D) { if (curve3D == null) { return(null); } Point3D point3D_1 = curve3D.GetStart(); if (point3D_1 == null) { return(null); } Point3D point3D_2 = curve3D.GetEnd(); if (point3D_2 == null) { return(null); } if (point3D_1 == point3D_2) { return(null); } return(Edge.ByStartVertexEndVertex(ToTopologic(point3D_1), ToTopologic(point3D_2))); }
public static List <ISegmentable3D> ExtremeSegmentable3Ds(this IEnumerable <ISegmentable3D> segmentable3Ds, IEnumerable <ISegmentable3D> segmentable3Ds_Auxiliary, double tolerance = Core.Tolerance.Distance) { if (segmentable3Ds == null || segmentable3Ds_Auxiliary == null) { return(null); } List <ISegmentable3D> result = new List <ISegmentable3D>(); Dictionary <ISegmentable3D, List <Vector3D> > dictionary = new Dictionary <ISegmentable3D, List <Vector3D> >(); foreach (ISegmentable3D segmentable3D in segmentable3Ds) { ICurve3D curve3D = segmentable3D as ICurve3D; if (curve3D == null) { continue; } foreach (Point3D point3D in new Point3D[] { curve3D.GetStart(), curve3D.GetEnd() }) { List <Point3D> point3Ds_Intersection = segmentable3D.Intersections(segmentable3Ds_Auxiliary, tolerance); Point3D point3D_Closest = point3Ds_Intersection.Closest(point3D); ISegmentable3D segmentable3D_Closest = null; foreach (ISegmentable3D segmentable3D_Temp in segmentable3Ds_Auxiliary) { if (segmentable3D_Temp.On(point3D_Closest, tolerance)) { segmentable3D_Closest = segmentable3D_Temp; break; } } if (segmentable3D_Closest != null) { if (!dictionary.TryGetValue(segmentable3D_Closest, out List <Vector3D> vector3Ds)) { vector3Ds = new List <Vector3D>(); dictionary[segmentable3D_Closest] = vector3Ds; } Vector3D vector3D = new Vector3D(point3D_Closest, point3D); if (vector3Ds.Find(x => x.AlmostEqual(vector3D, tolerance)) == null) { vector3Ds.Add(vector3D); ISegmentable3D segmentable3D_Moved = segmentable3D_Closest.GetMoved(vector3D) as ISegmentable3D; result.Add(segmentable3D_Moved); } } } } return(result); }
private static List <Face3D> Profiles_FromLocation(this Wall wall, double tolerance_Angle = Core.Tolerance.Angle, double tolerance_Distance = Core.Tolerance.Distance) { BoundingBoxXYZ boundingBoxXYZ = wall.get_BoundingBox(null); if (boundingBoxXYZ == null) { return(null); } LocationCurve locationCurve = wall.Location as LocationCurve; if (locationCurve == null) { return(null); } ICurve3D curve3D_Location = Convert.ToSAM(locationCurve); IEnumerable <ICurve3D> curves = null; if (curve3D_Location is ISegmentable3D) { curves = ((ISegmentable3D)curve3D_Location).GetSegments().Cast <ICurve3D>(); } else { curves = new List <ICurve3D>() { curve3D_Location } }; Vector3D direction = Vector3D.WorldZ; #if Revit2017 || Revit2018 || Revit2019 || Revit2020 double max = UnitUtils.ConvertFromInternalUnits(boundingBoxXYZ.Max.Z, DisplayUnitType.DUT_METERS); #else double max = UnitUtils.ConvertFromInternalUnits(boundingBoxXYZ.Max.Z, UnitTypeId.Meters); #endif Spatial.Plane plane_max = new Spatial.Plane(new Point3D(0, 0, max), direction); #if Revit2017 || Revit2018 || Revit2019 || Revit2020 double min = UnitUtils.ConvertFromInternalUnits(boundingBoxXYZ.Min.Z, DisplayUnitType.DUT_METERS); #else double min = UnitUtils.ConvertFromInternalUnits(boundingBoxXYZ.Min.Z, UnitTypeId.Meters); #endif Spatial.Plane plane_min = new Spatial.Plane(new Point3D(0, 0, min), direction); double height = max - min; Document document = wall.Document; //List<Face3D> face3Ds_Cutting = new List<Face3D>(); //Dictionary<ElementId, List<Face3D>> dictionary = GeneratingElementIdDictionary(wall); //foreach (KeyValuePair<ElementId, List<Face3D>> keyValuePair in dictionary) //{ // if (keyValuePair.Value == null || keyValuePair.Value.Count == 0) // { // continue; // } // HostObject hostObject_Cutting = document.GetElement(keyValuePair.Key) as HostObject; // if (hostObject_Cutting == null) // { // continue; // } // if (hostObject_Cutting is Floor || hostObject_Cutting is RoofBase) // { // List<Face3D> face3Ds_Temp = hostObject_Cutting.Profiles(); // if (face3Ds_Temp != null && face3Ds_Temp.Count != 0) // { // face3Ds_Cutting.AddRange(face3Ds_Temp); // } // } //} List <Face3D> result = new List <Face3D>(); foreach (ICurve3D curve3D in curves) { if (curve3D == null) { continue; } ICurve3D maxCurve = Spatial.Query.Project(plane_max, curve3D); ICurve3D minCurve = Spatial.Query.Project(plane_min, curve3D); Point3D point3D_1 = minCurve.GetEnd(); Point3D point3D_2 = maxCurve.GetStart(); Point3D point3D_3 = maxCurve.GetEnd(); Point3D point3D_4 = minCurve.GetStart(); if (point3D_1.Distance(point3D_3) < point3D_1.Distance(point3D_2)) { Point3D point_Temp = point3D_2; maxCurve.Reverse(); point3D_2 = point3D_3; point3D_3 = point_Temp; } List <Point3D> point3Ds = new List <Point3D>() { point3D_4, point3D_3, point3D_2, point3D_1 }; if (wall.Flipped) { point3Ds.Reverse(); } Face3D face3D = new Face3D(new Polygon3D(point3Ds, tolerance_Distance)); result.Add(face3D); //Spatial.Plane plane = Spatial.Create.Plane(point3Ds, tolerance_Distance); //if (plane == null) //{ // continue; //} //Vector3D vector3D = new Vector3D(point3D_4, point3D_3); //Segment2D segment2D = plane.Convert(new Segment3D(point3D_4, point3D_1)); //List<Segment2D> segment2Ds_Intersection = new List<Segment2D>(); //foreach (Face3D face3D_Cutting in face3Ds_Cutting) //{ // PlanarIntersectionResult planarIntersectionResult = Spatial.Create.PlanarIntersectionResult(plane, face3D_Cutting, tolerance_Angle, tolerance_Distance); // if (planarIntersectionResult == null || !planarIntersectionResult.Intersecting) // { // continue; // } // List<Segment2D> segment2Ds_Intersection_Temp = planarIntersectionResult.GetGeometry2Ds<Segment2D>(); // if (segment2Ds_Intersection_Temp != null && segment2Ds_Intersection_Temp.Count > 0) // { // segment2Ds_Intersection.AddRange(segment2Ds_Intersection_Temp); // } //} //List<Face2D> face2Ds = Profiles_From2D(segment2D, plane.Convert(vector3D), segment2Ds_Intersection, tolerance_Distance); //if (face2Ds != null && face2Ds.Count > 0) //{ // result.AddRange(face2Ds.ConvertAll(x => plane.Convert(x))); //} } if (result != null && result.Count > 0) { return(result); } return(result); }
public static List <Face3D> Profiles_Wall(this Wall wall) { if (wall == null) { return(null); } List <Face3D> result = Profiles_FromSketch(wall, !wall.Flipped); if (result != null && result.Count > 0) { return(result); } BoundingBoxXYZ boundingBoxXYZ = wall.get_BoundingBox(null); if (boundingBoxXYZ != null) { LocationCurve locationCurve = wall.Location as LocationCurve; if (locationCurve != null) { ICurve3D curve3D_Location = Convert.ToSAM(locationCurve); IEnumerable <ICurve3D> curves = null; if (curve3D_Location is ISegmentable3D) { curves = ((ISegmentable3D)curve3D_Location).GetSegments().Cast <ICurve3D>(); } else { curves = new List <ICurve3D>() { curve3D_Location } }; double max = UnitUtils.ConvertFromInternalUnits(boundingBoxXYZ.Max.Z, DisplayUnitType.DUT_METERS); Spatial.Plane plane_max = new Spatial.Plane(new Point3D(0, 0, max), new Vector3D(0, 0, 1)); double min = UnitUtils.ConvertFromInternalUnits(boundingBoxXYZ.Min.Z, DisplayUnitType.DUT_METERS); Spatial.Plane plane_min = new Spatial.Plane(new Point3D(0, 0, min), new Vector3D(0, 0, 1)); result = new List <Face3D>(); foreach (ICurve3D curve3D in curves) { if (curve3D == null) { continue; } ICurve3D maxCurve = plane_max.Project(curve3D); ICurve3D minCurve = plane_min.Project(curve3D); Point3D point3D_1 = minCurve.GetEnd(); Point3D point3D_2 = maxCurve.GetStart(); Point3D point3D_3 = maxCurve.GetEnd(); if (point3D_1.Distance(point3D_3) < point3D_1.Distance(point3D_2)) { Point3D point_Temp = point3D_2; maxCurve.Reverse(); point3D_2 = point3D_3; point3D_3 = point_Temp; } List <Point3D> point3Ds = new List <Point3D>() { minCurve.GetStart(), point3D_3, point3D_2, point3D_1 }; if (wall.Flipped) { point3Ds.Reverse(); } result.Add(new Face3D(new Polygon3D(point3Ds))); } if (result != null && result.Count > 0) { return(result); } } } if (!ExporterIFCUtils.HasElevationProfile(wall)) { return(null); } IList <CurveLoop> curveLoops = ExporterIFCUtils.GetElevationProfile(wall); if (curveLoops == null) { return(null); } result = new List <Face3D>(); foreach (CurveLoop curveLoop in curveLoops) { Polygon3D polygon3D = curveLoop.ToSAM_Polygon3D(); if (polygon3D != null) { result.Add(new Face3D(polygon3D)); } } return(result); }
public static Line ToRevit_Line(this ICurve3D curve3D) { return(Line.CreateBound(curve3D.GetStart().ToRevit(), curve3D.GetEnd().ToRevit())); }