public static double[] GetZValues(FeatureLine fl) { try { Point3dCollection pointsOnFL = fl.GetPoints(FeatureLinePointType.AllPoints); var mypoints = new List <double>(); foreach (Point3d item in pointsOnFL) { if (Math.Abs(item.Z) > 0.01) { mypoints.Add(item.Z); } } return(mypoints.ToArray()); } catch (Exception ex) { MessengerManager.MessengerManager.LogException(ex); } return(null); }
public static void SetNewPointElevation(FeatureLine fl, Point3d point, double elevationDelta) { // get all points on the Feature Line Point3dCollection pointsOnFL = fl.GetPoints(FeatureLinePointType.AllPoints); // find the closest point and index double distance = double.MaxValue; int index = 0; Point3d closestPointOnCurve = Point3d.Origin; for (int i = 0; i < pointsOnFL.Count; i++) { Point3d p = pointsOnFL[i]; if (p.DistanceTo(point) < distance) { distance = p.DistanceTo(point); closestPointOnCurve = p; index = i; } } // apply the delta fl.SetPointElevation(index, closestPointOnCurve.Z + elevationDelta); }
private static bool ZeroElevation(FeatureLine fl) { try { using (var tr = Active.StartTransaction()) { Point3dCollection pointsOnFL = fl.GetPoints(FeatureLinePointType.AllPoints); for (int i = 0; i < pointsOnFL.Count; i++) { if (Math.Abs(pointsOnFL[i].Z) < 0.01) { return(true); } } tr.Commit(); } } catch (Exception ex) { MessengerManager.MessengerManager.LogException(ex); } return(false); }
public static double GetElevationAtPoint(this FeatureLine featureLine, Point3d point) { Point3dCollection points = featureLine.GetPoints(FeatureLinePointType.AllPoints); //Se if point already exists foreach (Point3d point3d in points) { if (point3d.X == point.X && point3d.Y == point.Y) { return(point3d.Z); } } double targetParam = featureLine.GetParameterAtPoint(point); Point3d lastPoint = Point3d.Origin; //if not find closest point and interpolate between for (int i = 0; i < points.Count; i++) { Point3d testPoint = points[i]; double param = featureLine.GetParameterAtPoint(testPoint); if (targetParam < param) { break; } lastPoint = testPoint; } double additionalDistance = Math.Sqrt(Math.Pow(point.X - lastPoint.X, 2) + Math.Pow(point.Y - lastPoint.Y, 2)); double grade = featureLine.GetGradeOutAtPoint(lastPoint); return(lastPoint.Z + grade * additionalDistance); }
private static void ApplyElevationCorrection(FeatureLine fl, double mean, double flMaxElevation) { try { if (mean <= 0) { throw new ArgumentOutOfRangeException(nameof(mean)); } fl.UpgradeOpen(); COMS.MessengerManager.AddLog("Start ApplyElevationCorrection"); using (var tr = Active.StartTransaction()) { Point3dCollection pointsOnFL = fl.GetPoints(FeatureLinePointType.AllPoints); for (int i = 0; i < pointsOnFL.Count; i++) { Point3d p = pointsOnFL[i]; var diff = Math.Abs(flMaxElevation - p.Z); if (diff > MaxDiff) { try { fl.SetPointElevation(i, mean); COMS.MessengerManager.AddLog ("Changed Feature Line: " + fl.Name + " Old Elevation=" + p.Z + " New Elevation=" + mean); } catch (Exception ex) { COMS.MessengerManager.LogException(ex); } } } tr.Commit(); } COMS.MessengerManager.AddLog("End ApplyElevationCorrection"); } catch (Exception ex) { MessengerManager.MessengerManager.LogException(ex); } }
private List <Point3d> GetPointsOfElevationChange(SoilSurfaceContainer soilSurfaceContainer, FeatureLine existingLine, FeatureLine proposedLine) { List <Point3d> elevationPoints = new List <Point3d>(); elevationPoints.Add(StartPoint); foreach (Point3d point3d in existingLine.GetPoints(FeatureLinePointType.AllPoints)) { elevationPoints.Add(point3d); } foreach (Point3d point3d in proposedLine.GetPoints(FeatureLinePointType.AllPoints)) { elevationPoints.Add(point3d); } elevationPoints.Add(EndPoint); return(elevationPoints); }
//[CommandMethod("AddDataToSurfaces")] /// <summary> /// Adding data from PlanFeatures (character lines) to surfaces and also inser PointsCogoGrous to surfaces /// </summary> /// <param name="midOrdinate"></param> /// <param name="maxDist"></param> /// <param name="weedingDist"></param> /// <param name="weedingAngle"></param> public static void AddDataToSurfaces(double midOrdinate = 0.1, double maxDist = 10.0, double weedingDist = 0.1, double weedingAngle = 0.5) { //Document doc = doc_dyn.AcDocument; var CivilApp = CivilApplication.ActiveDocument; Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; //double midOrdinate = 0.1; double maxDist = 10.0; double weedingDist = 0.1; double weedingAngle = 0.5; -- if start as CommandMethod using (Transaction ts = db.TransactionManager.StartTransaction()) { try { foreach (ObjectId OneSiteItem in CivilApp.GetSiteIds()) { Site OneSite = ts.GetObject(OneSiteItem, OpenMode.ForRead) as Site; string Site_Name = OneSite.Name; //ed.WriteMessage("\n Site_Name =" + Site_Name); foreach (ObjectId OneSurfaceId in CivilApp.GetSurfaceIds()) { //ObjectId SurfaceId = new ObjectId(); TinSurface CurrentSurface = ts.GetObject(OneSurfaceId, OpenMode.ForWrite) as TinSurface; //ed.WriteMessage("\n OneSurf.Name =" + CurrentSurface.Name); if (CurrentSurface.Name == Site_Name) { ed.WriteMessage($"\n Site with surface's name {CurrentSurface.Name} is exist!"); //ed.WriteMessage("\n Start adding standard breaklines for " + CurrentSurface.Name); AddBreakLines(null); //ed.WriteMessage("\n Start adding point group for " + CurrentSurface.Name); AddPointsGroup(); //ed.WriteMessage("\n Start adding out boundary for " + CurrentSurface.Name); AddBreakLines("Out_Boundary"); //ed.WriteMessage("\n Start adding internal boundary for " + CurrentSurface.Name); AddBreakLines("Internal_Boundary"); CurrentSurface.Rebuild(); ed.WriteMessage("\n Start rebuilding for " + CurrentSurface.Name); void AddBreakLines(string TypeOfLines) { ObjectIdCollection GroupOfBreaklines = new ObjectIdCollection(); foreach (ObjectId OneFlineItem in OneSite.GetFeatureLineIds()) { FeatureLine OneFline = ts.GetObject(OneFlineItem, OpenMode.ForRead) as FeatureLine; string OneFline_Name = OneFline.Name; if (OneFline_Name.Contains("outer_") && TypeOfLines == "Out_Boundary") { ed.WriteMessage("\n Start adding outer boundary for " + OneFline_Name); CurrentSurface.BoundariesDefinition.AddBoundaries(OneFline.GetPoints(Autodesk.Civil.FeatureLinePointType.AllPoints), midOrdinate, Autodesk.Civil.SurfaceBoundaryType.Outer, true); } else if (OneFline_Name.Contains("void_") && TypeOfLines == "Internal_Boundary") { ed.WriteMessage("\n Start adding internal boundary for " + OneFline_Name); CurrentSurface.BoundariesDefinition.AddBoundaries(OneFline.GetPoints(Autodesk.Civil.FeatureLinePointType.AllPoints), midOrdinate, Autodesk.Civil.SurfaceBoundaryType.Hide, true); } else { GroupOfBreaklines.Add(OneFlineItem); } } if (TypeOfLines == null) { ed.WriteMessage("\n Start adding standard breaklines"); CurrentSurface.BreaklinesDefinition.AddStandardBreaklines(GroupOfBreaklines, midOrdinate, maxDist, weedingDist, weedingAngle); } } void AddPointsGroup() { CogoPointCollection CG_AllPoints = CivilApp.CogoPoints; foreach (ObjectId OneCogoItem in CG_AllPoints) { CogoPoint COGO_Single = ts.GetObject(OneCogoItem, OpenMode.ForRead) as CogoPoint; ObjectId CG_GroupId = COGO_Single.PrimaryPointGroupId; PointGroup CG_Group = ts.GetObject(CG_GroupId, OpenMode.ForRead) as PointGroup; if (CG_Group.Name == Site_Name) { ed.WriteMessage("\n COGO points group for surface's name was find - it's name = " + CG_Group.Name); CurrentSurface.PointGroupsDefinition.AddPointGroup(CG_GroupId); break; } } } break; } } } } catch (System.Exception e) { ed.WriteMessage(e.Message); } ts.Commit(); } }
// TODO: Port of existing code, requires refactoring immininently public void EstimateFFLFromSurface(CivSurface proposed) { Document acDoc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { DBObject obj = acTrans.GetObject(this.BaseObject, OpenMode.ForWrite); //Need to add the temp line to create feature line from it BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; ObjectId perimId = FeatureLine.Create("plot" + PlotId, obj.ObjectId); FeatureLine perim = acTrans.GetObject(perimId, OpenMode.ForWrite) as FeatureLine; perim.AssignElevationsFromSurface(proposed.Id, false); var points = perim.GetPoints(Autodesk.Civil.FeatureLinePointType.PIPoint); // TODO: Move to settings double FinishedFloorLevel = Math.Ceiling(perim.MaxElevation * 20) / 20 + 0.15; // TODO: Move to generation code //Ad the FFL Label // Create a multiline text object using (MText acMText = new MText()) { Solid3d Solid = new Solid3d(); DBObjectCollection coll = new DBObjectCollection(); coll.Add(obj); Solid.Extrude(((Region)Region.CreateFromCurves(coll)[0]), 1, 0); Point3d centroid = new Point3d(Solid.MassProperties.Centroid.X, Solid.MassProperties.Centroid.Y, 0); Solid.Dispose(); acMText.Location = centroid; acMText.Contents = "FFL = " + FinishedFloorLevel.ToString("F3"); //acMText.Rotation = Rotation; acMText.Height = 8; acMText.Attachment = AttachmentPoint.MiddleCenter; acBlkTblRec.AppendEntity(acMText); acTrans.AddNewlyCreatedDBObject(acMText, true); } // TODO: Move to generation code foreach (Point3d p in points) { using (MText acMText = new MText()) { Point3d insert = new Point3d(p.X, p.Y, 0); acMText.Location = insert; //Number of course int courses = (int)Math.Ceiling((double)(((FinishedFloorLevel - 0.15f - p.Z) / 0.075f))); if (courses > 0) { acMText.Contents = courses + " Courses"; acMText.Height = 4; acMText.Attachment = AttachmentPoint.TopRight; acBlkTblRec.AppendEntity(acMText); acTrans.AddNewlyCreatedDBObject(acMText, true); } } } //perim.Erase(); //obj.Erase(); acTrans.Commit(); } }
public void PlineToPlots() { Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; PromptSelectionOptions pso = new PromptSelectionOptions(); pso.SingleOnly = true; pso.RejectObjectsOnLockedLayers = true; PromptSelectionResult psr = acDoc.Editor.GetSelection(pso); if (psr.Status == PromptStatus.OK) { using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { CivSurface oSurface = null; //Get the target surface ObjectIdCollection SurfaceIds = CivilApplication.ActiveDocument.GetSurfaceIds(); foreach (ObjectId surfaceId in SurfaceIds) { CivSurface temp = surfaceId.GetObject(OpenMode.ForRead) as CivSurface; if (temp.Name == Civils.Constants.ProposedGroundName) { oSurface = temp; } } int plotCount = 0; foreach (SelectedObject so in psr.Value) { try { DBObject obj = acTrans.GetObject(so.ObjectId, OpenMode.ForWrite); if (obj is Curve) { plotCount++; //Polyline acPline = obj as Polyline; //Need to add the temp line to create feature line from it BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; ObjectId perimId = FeatureLine.Create("plot" + plotCount, obj.ObjectId); FeatureLine perim = acTrans.GetObject(perimId, OpenMode.ForWrite) as FeatureLine; perim.AssignElevationsFromSurface(oSurface.Id, false); var points = perim.GetPoints(Autodesk.Civil.FeatureLinePointType.PIPoint); double FinishedFloorLevel = Math.Ceiling(perim.MaxElevation * 20) / 20 + 0.15; //Ad the FFL Label // Create a multiline text object using (MText acMText = new MText()) { Solid3d Solid = new Solid3d(); DBObjectCollection coll = new DBObjectCollection(); coll.Add(obj); Solid.Extrude(((Region)Region.CreateFromCurves(coll)[0]), 1, 0); Point3d centroid = new Point3d(Solid.MassProperties.Centroid.X, Solid.MassProperties.Centroid.Y, 0); Solid.Dispose(); acMText.Location = centroid; acMText.Contents = "FFL = " + FinishedFloorLevel.ToString("F3"); //acMText.Rotation = Rotation; acMText.Height = 8; acMText.Attachment = AttachmentPoint.MiddleCenter; acBlkTblRec.AppendEntity(acMText); acTrans.AddNewlyCreatedDBObject(acMText, true); } foreach (Point3d p in points) { using (MText acMText = new MText()) { Point3d insert = new Point3d(p.X, p.Y, 0); acMText.Location = insert; //Number of course int courses = (int)Math.Ceiling((double)(((FinishedFloorLevel - 0.15f - p.Z) / 0.075f))); if (courses > 0) { acMText.Contents = courses + " Courses"; acMText.Height = 4; acMText.Attachment = AttachmentPoint.TopRight; acBlkTblRec.AppendEntity(acMText); acTrans.AddNewlyCreatedDBObject(acMText, true); } } } //perim.Erase(); obj.Erase(); } else { acDoc.Editor.WriteMessage("Object is not a polyline\n"); } } catch (Autodesk.AutoCAD.Runtime.Exception e) { acDoc.Editor.WriteMessage(e.Message + "\n"); } catch (System.Exception e) { acDoc.Editor.WriteMessage(e.Message + "\n"); } } acTrans.Commit(); } } }
/// <summary> /// Corrects the water featurelines. /// Has been omitted until further notice due to 25 swings in elevation for wier and structures /// </summary> /// <param name="fl">The fl.</param> /// <param name="mean">The mean.</param> /// <exception cref="System.ArgumentOutOfRangeException"></exception> public static void CorrectWaterFeaturelines(FeatureLine fl, double mean) { try { if (mean <= 0) { throw new ArgumentOutOfRangeException(nameof(mean)); } fl.UpgradeOpen(); if (fl.Layer.Contains("S-WATER")) { using (var tr = Active.StartTransaction()) { Point3dCollection pointsOnFL = fl.GetPoints(FeatureLinePointType.AllPoints); COMS.MessengerManager.AddLog("Start CorrectWaterFeaturelines"); for (int i = 0; i < pointsOnFL.Count; i++) { Point3d p = pointsOnFL[i]; var last = pointsOnFL.Count - 1; var diff = Math.Abs(p.Z - mean); if ((diff > MaxWater) && (Math.Abs(mean) > 0.01)) { COMS.MessengerManager.AddLog("S-Changed to Mean = " + mean); try { if (i != last) { fl.SetPointElevation(i, mean); } } catch (System.ArgumentOutOfRangeException) { } catch (Exception ex) { MessengerManager.MessengerManager.LogException(ex); MessengerManager.MessengerManager.AddLog("Failure = " + i + "and Mean = " + mean); } COMS.MessengerManager.AddLog("E-Changed to Mean = " + mean); } } tr.Commit(); } } COMS.MessengerManager.AddLog("End CorrectWaterFeaturelines"); } catch (Exception ex) { MessengerManager.MessengerManager.LogException(ex); } }