/// <summary> /// Gets the polyline points. /// </summary> /// <param name="poid">The poid.</param> /// <returns>Point2dCollection.</returns> private static Point2dCollection GetPolylinePoints(Acaddb.ObjectId poid) { Point2dCollection points; using (Acaddb.Transaction tr = Active.StartTransaction()) { points = new Point2dCollection(); Acaddb.DBObject obj = tr.GetObject(poid, Acaddb.OpenMode.ForRead); Acaddb.Polyline lwp = obj as Acaddb.Polyline; if (lwp != null) { if (lwp.Closed) { int vn = lwp.NumberOfVertices; for (int i = 0; i < vn; i++) { Point2d pt = lwp.GetPoint2dAt(i); points.Add(pt); } } } } return(points); }
/// <summary> /// Gets the polyline. /// </summary> /// <param name="poid">The poid.</param> /// <returns>Acaddb.Polyline.</returns> private static Acaddb.Polyline GetPolyline(Acaddb.ObjectId poid) { using (Acaddb.Transaction tr = Active.StartTransaction()) { Acaddb.DBObject obj = tr.GetObject(poid, Acaddb.OpenMode.ForRead); Acaddb.Polyline lwp = obj as Acaddb.Polyline; if (lwp != null) { if (lwp.Closed) { return(lwp); } } } return(null); }
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); }