Outline closed Polylines in Autocad.net

Outline closed Polylines in Autocad.net

imagination_s
Advocate Advocate
3,095 Views
7 Replies
Message 1 of 8

Outline closed Polylines in Autocad.net

imagination_s
Advocate
Advocate

Hello everyone,

please hel me with a problem.Is there a way to make a outline in C# or VB.net for some closed polyline .Something like in this picture :Snap 2021-08-30 at 09.25.45.png

 

 

Thank you for your support and your help.

Accepted solutions (1)
3,096 Views
7 Replies
Replies (7)
Message 2 of 8

_gile
Consultant
Consultant
Accepted solution

Hi,

You can use the following method and struct (which is a generalization of this one).

struct Segment
{
    public Point2d StartPt { get; set; }
    public Point2d EndPt { get; set; }
    public double Bulge { get; set; }
}

public static IEnumerable<Polyline> Union(IEnumerable<Polyline> plines)
{
    foreach (var group in plines.GroupBy(pl => new { pl.Elevation, pl.Normal }))
    {
        if (group.Count() == 1)
        {
            yield return group.First();
        }
        else
        {
            var plane = new Plane(Point3d.Origin, group.Key.Normal);
            var segs = new List<Segment>();
            using (var dbObjects = new DBObjectCollection())
            {
                foreach (var pline in group)
                {
                    pline.Explode(dbObjects);
                }
                using (DBObjectCollection regions = Region.CreateFromCurves(dbObjects))
                {
                    var region = (Region)regions[0];
                    for (int i = 1; i < regions.Count; i++)
                    {
                        region.BooleanOperation(BooleanOperationType.BoolUnite, (Region)regions[i]);
                        regions[i].Dispose();
                    }
                    foreach (DBObject o in dbObjects) o.Dispose();
                    dbObjects.Clear();
                    region.Explode(dbObjects);
                    region.Dispose();
                    for (int i = 0; i < dbObjects.Count; i++)
                    {
                        if (dbObjects[i] is Region)
                        {
                            ((Region)dbObjects[i]).Explode(dbObjects);
                            continue;
                        }
                        var curve = (Curve)dbObjects[i];
                        Point3d start = curve.StartPoint;
                        Point3d end = curve.EndPoint;
                        double bulge = 0.0;
                        if (curve is Arc)
                        {
                            Arc arc = (Arc)curve;
                            double angle = arc.Center.GetVectorTo(start).GetAngleTo(arc.Center.GetVectorTo(end), arc.Normal);
                            bulge = Math.Tan(angle / 4.0);
                        }
                        segs.Add(new Segment { StartPt = start.Convert2d(plane), EndPt = end.Convert2d(plane), Bulge = bulge });
                    }
                    foreach (DBObject obj in dbObjects) obj.Dispose();
                    while (segs.Count > 0)
                    {
                        using (Polyline pline = new Polyline())
                        {
                            pline.AddVertexAt(0, segs[0].StartPt, segs[0].Bulge, 0.0, 0.0);
                            Point2d pt = segs[0].EndPt;
                            segs.RemoveAt(0);
                            int vtx = 1;
                            while (true)
                            {
                                int i = segs.FindIndex(delegate (Segment s)
                                {
                                    return s.StartPt.IsEqualTo(pt) || s.EndPt.IsEqualTo(pt);
                                });
                                if (i < 0) break;
                                Segment seg = segs[i];
                                if (seg.EndPt.IsEqualTo(pt))
                                    seg = new Segment { StartPt = seg.EndPt, EndPt = seg.StartPt, Bulge = -seg.Bulge };
                                pline.AddVertexAt(vtx, seg.StartPt, seg.Bulge, 0.0, 0.0);
                                pt = seg.EndPt;
                                segs.RemoveAt(i);
                                vtx++;
                            }
                            pline.Closed = true;
                            pline.Normal = group.Key.Normal;
                            pline.Elevation = group.Key.Elevation;
                            yield return pline;
                        }
                    }
                }
            }
        }
    }
}


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 8

imagination_s
Advocate
Advocate

Thankyou so much Sir for your help.Your code work so greate.Here is a picture of some polylines .After apply the code it creates a single polyline .Have  a nice day 🙂

Snap 2021-08-31 at 11.59.57.png

 

0 Likes
Message 4 of 8

anhtuan891997
Community Visitor
Community Visitor

Hello! Can you show the entire code to create an outline like your image?

0 Likes
Message 5 of 8

_gile
Consultant
Consultant

@anhtuan891997  a écrit :

Hello! Can you show the entire code to create an outline like your image?


Here's an example:

using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;

using System;
using System.Collections.Generic;
using System.Linq;

using AcAp = Autodesk.AutoCAD.ApplicationServices.Core.Application;

namespace UnionPlinesSample
{
    public class Commands
    {
        [CommandMethod("TEST")]
        public static void Test()
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;

            var filter = new SelectionFilter(new[] {
                new TypedValue(0, "LWPOLYLINE"),
                new TypedValue(-4, "&"),
                new TypedValue(70, 1) });
            var selection = ed.GetSelection(filter);
            if (selection.Status == PromptStatus.OK)
            {
                var options = new PromptKeywordOptions("\nErase source polylines [Yes/No]", "Yes No");
                var kWord = ed.GetKeywords(options);
                if (kWord.Status == PromptStatus.OK)
                {
                    using (var tr = db.TransactionManager.StartOpenCloseTransaction())
                    {
                        var source = selection.Value
                            .GetObjectIds()
                            .Select(id => (Polyline)tr.GetObject(id, OpenMode.ForRead));
                        var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                        foreach (var pline in Union(source))
                        {
                            curSpace.AppendEntity(pline);
                            tr.AddNewlyCreatedDBObject(pline, true);
                        }
                        if (kWord.StringResult == "Yes")
                        {
                            foreach (var pline in source)
                            {
                                pline.UpgradeOpen();
                                pline.Erase();
                            }
                        }
                        tr.Commit();
                    }
                }
            }
        }

        struct Segment
        {
            public Point2d StartPt { get; set; }
            public Point2d EndPt { get; set; }
            public double Bulge { get; set; }
        }

        public static IEnumerable<Polyline> Union(IEnumerable<Polyline> plines)
        {
            foreach (var group in plines.GroupBy(pl => new { pl.Elevation, pl.Normal }))
            {
                if (group.Count() == 1)
                {
                    yield return group.First();
                }
                else
                {
                    var plane = new Plane(Point3d.Origin, group.Key.Normal);
                    var segs = new List<Segment>();
                    using (var dbObjects = new DBObjectCollection())
                    {
                        foreach (var pline in group)
                        {
                            pline.Explode(dbObjects);
                        }
                        using (DBObjectCollection regions = Region.CreateFromCurves(dbObjects))
                        {
                            var region = (Region)regions[0];
                            for (int i = 1; i < regions.Count; i++)
                            {
                                region.BooleanOperation(BooleanOperationType.BoolUnite, (Region)regions[i]);
                                regions[i].Dispose();
                            }
                            foreach (DBObject o in dbObjects) o.Dispose();
                            dbObjects.Clear();
                            region.Explode(dbObjects);
                            region.Dispose();
                            for (int i = 0; i < dbObjects.Count; i++)
                            {
                                if (dbObjects[i] is Region)
                                {
                                    ((Region)dbObjects[i]).Explode(dbObjects);
                                    continue;
                                }
                                var curve = (Curve)dbObjects[i];
                                Point3d start = curve.StartPoint;
                                Point3d end = curve.EndPoint;
                                double bulge = 0.0;
                                if (curve is Arc)
                                {
                                    Arc arc = (Arc)curve;
                                    double angle = arc.Center.GetVectorTo(start).GetAngleTo(arc.Center.GetVectorTo(end), arc.Normal);
                                    bulge = Math.Tan(angle / 4.0);
                                }
                                segs.Add(new Segment { StartPt = start.Convert2d(plane), EndPt = end.Convert2d(plane), Bulge = bulge });
                            }
                            foreach (DBObject obj in dbObjects) obj.Dispose();
                            while (segs.Count > 0)
                            {
                                using (Polyline pline = new Polyline())
                                {
                                    pline.AddVertexAt(0, segs[0].StartPt, segs[0].Bulge, 0.0, 0.0);
                                    Point2d pt = segs[0].EndPt;
                                    segs.RemoveAt(0);
                                    int vtx = 1;
                                    while (true)
                                    {
                                        int i = segs.FindIndex(delegate (Segment s)
                                        {
                                            return s.StartPt.IsEqualTo(pt) || s.EndPt.IsEqualTo(pt);
                                        });
                                        if (i < 0) break;
                                        Segment seg = segs[i];
                                        if (seg.EndPt.IsEqualTo(pt))
                                            seg = new Segment { StartPt = seg.EndPt, EndPt = seg.StartPt, Bulge = -seg.Bulge };
                                        pline.AddVertexAt(vtx, seg.StartPt, seg.Bulge, 0.0, 0.0);
                                        pt = seg.EndPt;
                                        segs.RemoveAt(i);
                                        vtx++;
                                    }
                                    pline.Closed = true;
                                    pline.Normal = group.Key.Normal;
                                    pline.Elevation = group.Key.Elevation;
                                    yield return pline;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 6 of 8

imagination_s
Advocate
Advocate

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

0 Likes
Message 7 of 8

imagination_s
Advocate
Advocate

Hello  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

0 Likes
Message 8 of 8

kerry_w_brown
Advisor
Advisor

Can you please use the code formatting feature !

 

public void make_buffer(Polyline3d poly, double buffer, string detination_layer)

{  // . . .  }

 

_kdub_0-1659076727432.png

 

Click the button.

A dialog opens .

Add the code ( paste ) into the dialog.

 

Regards,

 

 

 


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12 : class keyThumper<T> : Lazy<T>;      another  Swamper
0 Likes