Hi,
Assuming all segments of the region boundary are line segments, you can the Brep (Boundary REPresentation) API (requires referencing the acdbmgdbrep.dll) to get the region edges first vertices.
Here's an example:
using Autodesk.AutoCAD.BoundaryRepresentation;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using System.Linq;
using AcAp = Autodesk.AutoCAD.ApplicationServices.Core.Application;
namespace RegionToPolyline
{
public class Commands
{
[CommandMethod("TEST")]
public static void Test()
{
var doc = AcAp.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
var options = new PromptEntityOptions("\nSelect Region: ");
options.SetRejectMessage("\nSelected object is nor a Region.");
options.AddAllowedClass(typeof(Region), true);
var result = ed.GetEntity(options);
if (result.Status != PromptStatus.OK)
return;
using (var tr = db.TransactionManager.StartTransaction())
{
var region = (Region)tr.GetObject(result.ObjectId, OpenMode.ForWrite);
var normal = region.Normal;
var plane = new Plane(Point3d.Origin, normal);
Point2d[] points;
using (var brep = new Brep(region))
{
points = brep.Edges.Select(e => e.Vertex1.Point.Convert2d(plane)).ToArray();
}
region.Erase();
using (var pline = new Polyline(points.Length))
{
for (int i = 0; i < points.Length; i++)
{
pline.AddVertexAt(i, points[i], 0.0, 0.0, 0.0);
}
pline.Closed = true;
pline.Normal = normal;
var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
curSpace.AppendEntity(pline);
tr.AddNewlyCreatedDBObject(pline, true);
}
tr.Commit();
}
}
}
}