Hello _gile here my function of making outline of a polyline
public void make_buffer(Polyline3d poly, double buffer, string detination_layer)
{
try
{
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; //citire dwg curent
Database acCurDB = acDoc.Database;
using (DocumentLock acDocloc = acDoc.LockDocument())
{
using (var tr = acCurDB.TransactionManager.StartTransaction())
{
BlockTable acBlkTbl;
acBlkTbl = (BlockTable)tr.GetObject(acCurDB.BlockTableId, OpenMode.ForRead);
DwgReader reader = new DwgReader();
DwgWriter writer = new DwgWriter();
IGeometry geometry = reader.ReadGeometry(poly);
if(!geometry.IsEmpty || geometry!=null)
{
//Tangent_Lines_distance(1, p3d,5);
// IGeometry buf = geometry.Buffer(dblOptionsResult.Value);
IGeometry buf = geometry.Buffer(buffer);//buffer
MPolygon outEnt = null;
if (!buf.IsEmpty)
{
if (buf.GeometryType == "Polygon")
{
outEnt = writer.WriteMPolygon(buf as Polygon);
}
else if (buf.GeometryType == "MultiPolygon")
{
outEnt = writer.WriteMPolygon(buf as MultiPolygon);
}
}
if (outEnt != null)
{
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
outEnt.ColorIndex = 1;
outEnt.Layer = detination_layer;
DBObjectCollection acDBObjColl = new DBObjectCollection();
//for(int i=0;i< outEnt.NumMPolygonLoops;i++)
// {
// MPolygonLoop mloop = outEnt.GetMPolygonLoopAt(i);
// outEnt.RemoveMPolygonLoopAt
// IntegerCollection col= outEnt.IsPointInsideMPolygon(new Point3d(), 0);
// }
btr.AppendEntity(outEnt);
tr.AddNewlyCreatedDBObject(outEnt, true);
outEnt.Explode(acDBObjColl);
outEnt.Erase();
foreach (Entity acEnt in acDBObjColl)
{
// ' Add the new object to the block table record and the transaction
acEnt.Layer = detination_layer;
acEnt.ColorIndex = 1;
btr.AppendEntity(acEnt);
tr.AddNewlyCreatedDBObject(acEnt, true);
}
}
tr.Commit();
tr.Dispose();
}
}
}
}
catch (System.Exception ex)
{
// MessageBox.Show(ex.ToString());
// poly.Highlight();
return;
}
}
//here the function for manage the outlines
public void OutPlines()
{
Document _doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; //citire dwg curent
Database db = _doc.Database;
using (DocumentLock acDocloc = _doc.LockDocument())
{
// Polyline result_buffer = MinimumEnclosingBoundary(false);
//Point3d center = GetCentroid(result_buffer);
//string strPt = center.X.ToString() + "," + center.Y.ToString();
Editor ed = _doc.Editor;
var acTypVal = new TypedValue[2];
acTypVal.SetValue(new TypedValue((int)DxfCode.Start, "LWPOLYLINE"), 0);
acTypVal.SetValue(new TypedValue((int)DxfCode.LayerName, "Buffer"), 1);
SelectionFilter filter = new SelectionFilter(acTypVal);
PromptSelectionResult psr = ed.SelectAll(filter);
if (psr.Status != PromptStatus.OK)
return;
//else
// {
// MessageBox.Show("nothing found on layer Buffer");
// }
bool erase = true;
try
{
ObjectIdCollection ids = new ObjectIdCollection(psr.Value.GetObjectIds());
ListEcho.Items.Add("Outlines is creating .Please wait.....");
int n = MergePlines(ids, erase);
ListEcho.Items.Add("here where made" + n + " polylines(i) ");
// ed.WriteMessage("\n{0} there where made (i){1} polylines", n, n > 1 ? "s" : "");
MessageBox.Show("done");
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
ed.WriteMessage("\n{0}: {1}\n{2}", ex.Message, ex.StackTrace);
}
}
}
//here is the buton function to execut all that
Polyline3d source = null;
try
{
this.Hide();
var doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
double distance = Convert.ToDouble(textBox_distance.Text);
using (DocumentLock acDocloc = doc.LockDocument())
{
using (var tr = db.TransactionManager.StartTransaction())
{
var acTypValAx = new TypedValue[2];
acTypValAx.SetValue(new TypedValue((int)DxfCode.Start, "Polyline"), 0);
acTypValAx.SetValue(new TypedValue((int)DxfCode.LayerName, ComboAx.SelectedItem.ToString()), 1);
var acSelFtrCarosabil = new SelectionFilter(acTypValAx);
PromptSelectionResult resultAx = ed.GetSelection(acSelFtrCarosabil);
if (resultAx.Status == PromptStatus.OK)
{
SelectionSet acSSet = resultAx.Value;
ObjectId[] idarray = acSSet.GetObjectIds();
foreach (ObjectId objid in idarray)
{
source = (Polyline3d)tr.GetObject(objid, OpenMode.ForRead);
//Extents3d ext = pl3d.GeometricExtents;
//Zoom_me(ed, ext.MinPoint, ext.MaxPoint);
AcadApplication app = (AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
app.ZoomExtents();
Tangent_Lines_distance(1, source, distance);
}
}
this.Show();
//ia toate polylininile din bufferul de distana si punele in lista
List<Polyline3d> get_poly3d = get_polylines();
// ListEcho.Items.Add(get_poly3d.Count.ToString());
//calculeaza distanta minima de la fiecare polylinie la ax
foreach (Polyline3d dest in get_poly3d)
{
// GetMinimumDistance_boundinBox(source, dest);
// Polyline bounding= MinimumEnclosingBoundary(dest);
if (dest.Layer.ToUpper() == "mylayer")
{
Curve pl1 = pl1 = (Curve)tr.GetObject(source.ObjectId, OpenMode.ForRead);
Curve pl2 = (Curve)tr.GetObject(dest.ObjectId, OpenMode.ForRead);
double distance_to_carosabil = pl1.GetGeCurve().GetDistanceTo(pl2.GetGeCurve());
// ed.WriteMessage(distance_to_carosabil+ "\n");
make_buffer(dest, Math.Round(distance_to_carosabil *2), "Buffer");
break;
}
}
foreach (Polyline3d dest in get_poly3d)
{
// GetMinimumDistance_boundinBox(source, dest);
// Polyline bounding= MinimumEnclosingBoundary(dest);
Curve pl1 = pl1 = (Curve)tr.GetObject(source.ObjectId, OpenMode.ForRead);
Curve pl2 = (Curve)tr.GetObject(dest.ObjectId, OpenMode.ForRead);
//Curve pl2 = (Curve)tr.GetObject(bounding.ObjectId, OpenMode.ForRead);
Extents3d ext_source = pl1.GeometricExtents;
Extents3d ext_dest = pl2.GeometricExtents;
//double d = ext_source.MaxPoint.DistanceTo(ext_dest.MaxPoint);
//ListEcho.Items.Add(d.ToString());
// ed.WriteMessage(difference.ToString() + "\r");
//get distance to boundinbox
double distance_buf = pl1.GetGeCurve().GetDistanceTo(pl2.GetGeCurve());
if (dest.Layer.ToUpper() == "mylayer")
{
}
// ListEcho.Items.Add(distance_buf.ToString());
// ed.WriteMessage(distance_buf + "\n");
//result_buffer.UpgradeOpen();
//result_buffer.Erase();
//if (distance_buf < 1)
//{
// dest.Highlight();
//}
if (distance_buf >1)
{
// ed.WriteMessage(distance_buf + "\n");
make_buffer(dest, Math.Round(distance_buf+2.5), "Buffer");
}
}
ListEcho.Items.Add("Am procesat " + get_poly3d.Count.ToString() + " polilinii");
tr.Commit();
tr.Dispose();
}
}
// MessageBox.Show("Done");
}
catch(System.Exception ex)
{
MessageBox.Show(ex.ToString());
}
OutPlines();
the program make reference to exlude a specific layer so that it amke the outline of an area
hpe this helps