public static void CheckElevFromFeatureLine(Acaddb.ObjectId featureId) { var mean = 0.0; using (Acaddb.Transaction tr = Active.StartTransaction()) { var feature = (Autodesk.Civil.DatabaseServices.FeatureLine)featureId.GetObject(Acaddb.OpenMode.ForRead); if (feature == null) { return; } if (feature != null) { SendMessage(feature); try { mean = GetAverageElev(feature); } catch { } if (Math.Abs(mean) <= 0.01) { goto Skip; } if (ZeroElevation(feature)) { COMS.MessengerManager.AddLog("Starting Checking Zero Elevation > 20 Points"); if (feature.GetPoints(FeatureLinePointType.AllPoints).Cast <Point3d>().Count(p => Math.Abs(p.Z) < 0.001) < 20) { COMS.MessengerManager.AddLog("Starting Correcting Zero Elevation > 20 Points"); ApplyElevationCorrection(feature, mean, feature.MaxElevation); COMS.MessengerManager.AddLog("Ending Correcting Zero Elevation > 20 Points"); } COMS.MessengerManager.AddLog("Ending Checking Zero Elevation > 20 Points"); } SendMessage(feature); } Skip: tr.Commit(); } COMS.MessengerManager.AddLog("End CheckElevFromFeatureLine"); }
public static Acaddb.ObjectId ScaleNewPolylineObject(Point2dCollection points) { var offset = -0.001; var newoid = Acaddb.ObjectId.Null; var doc = Active.Document; try { // Get the current document and database Document acDoc = Application.DocumentManager.MdiActiveDocument; Acaddb.Database acCurDb = acDoc.Database; using (acDoc.LockDocument()) { // Start a transaction using (Acaddb.Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { // Open the Block table for read Acaddb.BlockTable acBlkTbl; acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, Acaddb.OpenMode.ForRead) as Acaddb.BlockTable; // Open the Block table record Model space for write Acaddb.BlockTableRecord acBlkTblRec; acBlkTblRec = acTrans.GetObject(acBlkTbl[Acaddb.BlockTableRecord.ModelSpace], Acaddb.OpenMode.ForWrite) as Acaddb.BlockTableRecord; // Create a lightweight polyline using (Acaddb.Polyline acPoly = new Acaddb.Polyline()) { int i = 0; foreach (Point2d pnt in points) { acPoly.AddVertexAt(i++, pnt, 0, 0, 0); } // Close the polyline acPoly.Closed = true; SendPolylineMessage("Length Info Before", acPoly); var centroid = GetCentroidOfOuterBoundary(points); var centroid3d = new Point3d(centroid.X, centroid.Y, 0.0); var closepnt = acPoly.GetClosestPointTo(centroid3d, true); var radius = acPoly.GetDistAtPoint(closepnt); var scaleFac = 1 + (offset / Math.Abs(radius)); acPoly.TransformBy(Matrix3d.Scaling(scaleFac, new Point3d(centroid.X, centroid.Y, 0))); SendPolylineMessage("Length Info After", acPoly); // Add the new object to the block table record and the transaction newoid = acBlkTblRec.AppendEntity(acPoly); acTrans.AddNewlyCreatedDBObject(acPoly, true); // Save the new objects to the database acTrans.Commit(); } } } } catch (Exception ex) { MessengerManager.MessengerManager.LogException(ex); } return(newoid); }