Message 1 of 3
Remove unnecessary points in curveloop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; Reference reference = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element); Room room = doc.GetElement(reference) as Room; List<CurveLoop> curveLoops = GetRoomBoundry(room); List<XYZ> points = new List<XYZ>(); List<XYZ> pointsToRemove = new List<XYZ>(); double threshold = 0.1; foreach (Curve curve in curveLoops[0]) { points.Add(curve.GetEndPoint(0)); } for (int i = 1; i < points.Count-1; i++) { XYZ previous = points[i - 1]; XYZ current = points[i]; XYZ next = points[i + 1]; double nextToPrevious = DistanceBetweenPoints(previous, next); double ordinal = DistanceBetweenPoints(previous, current) + DistanceBetweenPoints(current, next); if (Math.Abs(nextToPrevious - ordinal) < threshold) { pointsToRemove.Add(points[i]); } } if(pointsToRemove.Count>0) { foreach (XYZ point in pointsToRemove) { LineUtils.DrawMarker(doc, point); } } return Result.Succeeded; } public double DistanceBetweenPoints(XYZ firstPoint,XYZ secondPoint) { Line line = Line.CreateBound(firstPoint, secondPoint); return line.ApproximateLength; } public static List<CurveLoop> GetRoomBoundry(Room room) { Document doc = room.Document; List<CurveLoop> curveLoops = new List<CurveLoop>(); CurveLoop curveLoop = null; IList<IList<Autodesk.Revit.DB.BoundarySegment>> loops = room.GetBoundarySegments(new SpatialElementBoundaryOptions()); foreach (IList<Autodesk.Revit.DB.BoundarySegment> loop in loops) { IList<Curve> curveList = new List<Curve>(); foreach (Autodesk.Revit.DB.BoundarySegment seg in loop) { Curve curve = seg.GetCurve(); XYZ p = curve.GetEndPoint(0); XYZ q = curve.GetEndPoint(1); Line line = Line.CreateBound(p, q); curveList.Add(Line.CreateBound(p, q)); } curveLoop = CurveLoop.Create(curveList); curveLoops.Add(curveLoop); } return curveLoops; }
Hello friends
I want to remove unnecessery point from my curveloop
ın image below i mark the points i dont need.
But some curveloops i cant find the all unnecessery points
How can i solve this?
Is there any smarter algorithm?
Thanks in advance....