public void CreateFromPolyline() { using (Transaction trans = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction()) { try { PromptEntityOptions promptEntOp = new PromptEntityOptions("Select a Polyline : "); PromptEntityResult promptEntRs = default(PromptEntityResult); promptEntRs = Active.Editor.GetEntity(promptEntOp); if (promptEntRs.Status != PromptStatus.OK) { Active.Editor.WriteMessage("Exiting! Try Again !"); return; } ObjectId idEnt = default(ObjectId); idEnt = promptEntRs.ObjectId; ObjectId oFtrLn = FeatureLine.Create("Test", idEnt); trans.Commit(); } catch (Exception ex) { Active.Editor.WriteMessage("Error : ", ex.Message); } } }
public FeatureLine GetFeatureLine(ObjectId curve, CivSurface targetSurface) { Database acCurDb = _hostDocument.Database; Transaction acTrans = acCurDb.TransactionManager.TopTransaction; ObjectId perimId = FeatureLine.Create(Guid.NewGuid().ToString(), curve); FeatureLine perim = acTrans.GetObject(perimId, OpenMode.ForWrite) as FeatureLine; perim.AssignElevationsFromSurface(targetSurface.Id, true); return(perim); }
// TODO: Revoew this method /*private SurfaceProperties? ExtractSurfaceInformation(CivSurface targetSurface) * { * Document acDoc = Application.DocumentManager.MdiActiveDocument; * Database acCurDb = acDoc.Database; * Transaction acTrans = acCurDb.TransactionManager.TopTransaction; * Polyline boundary = (Polyline) acTrans.GetObject(this.BaseObject, OpenMode.ForRead); * * Point2dCollection points = new Point2dCollection(); * for (int i = 0, size = boundary.NumberOfVertices; i < size; i++) * points.Add(boundary.GetPoint2dAt(i)); * * SurfaceProperties result = new SurfaceProperties(); * * using (Database destDb = new Database(true, true)) * { * using (Transaction transDest = destDb.TransactionManager.StartTransaction()) * { * * Database db = Application.DocumentManager.MdiActiveDocument.Database; * HostApplicationServices.WorkingDatabase = destDb; * * // TODO: Review if exception handling is the answer * ObjectId newSurfaceId; * try * { * // This errors out when surface has ben copied * newSurfaceId = TinSurface.CreateByCropping(destDb, "Surface<[Next Counter(CP)]>", * targetSurface.ObjectId, points); * * TinSurface newSurface = transDest.GetObject(newSurfaceId, OpenMode.ForRead) as TinSurface; * GeneralSurfaceProperties genProps = newSurface.GetGeneralProperties(); * result.MaxElevation = genProps.MaximumElevation; * result.MinElevation = genProps.MinimumElevation; * } * catch (SurfaceException e) * { * return null; * } * finally * { * HostApplicationServices.WorkingDatabase = db; * } * } * } * * return result; * }*/ public FeatureLine GetPerim(CivSurface targetSurface) { Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; Transaction acTrans = acCurDb.TransactionManager.TopTransaction; //Polyline boundary = (Polyline) acTrans.GetObject(this.BaseObject, OpenMode.ForRead); ObjectId perimId = FeatureLine.Create(Guid.NewGuid().ToString(), this.BaseObject); FeatureLine perim = acTrans.GetObject(perimId, OpenMode.ForWrite) as FeatureLine; perim.AssignElevationsFromSurface(targetSurface.Id, true); return(perim); }
public static Polyline3d AlignmentToPolyline3d2(Alignment alignment, Profile profile) { Point3d point; Polyline3d p3d = null; var elevations = new Point3dCollection(); var station = 0d; double elevation; var db = alignment.Database; using (var tr = db.TransactionManager.StartTransaction()) { var polylineId = alignment.GetPolyline(); using (var polyline = tr.GetObject(polylineId, OpenMode.ForRead) as Polyline) { do { station += 0.001; if (station > polyline.Length) { station = polyline.Length; } elevation = profile.ElevationAt(station); point = polyline.GetPointAtDist(station); point = new Point3d(point.X, point.Y, elevation); elevations.Add(point); } while (station < polyline.Length); var fid = FeatureLine.Create("george", polylineId); var featureLine = tr.GetObject(fid, OpenMode.ForWrite) as FeatureLine; foreach (Point3d p in elevations) { featureLine.InsertElevationPoint(p); } var objs = new DBObjectCollection(); featureLine.Explode(objs); p3d = new Polyline3d(Poly3dType.SimplePoly, elevations, polyline.Closed); } } return(p3d); }
// 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(); } } }