Snap check

Snap check

giskumar
Enthusiast Enthusiast
996 Views
3 Replies
Message 1 of 4

Snap check

giskumar
Enthusiast
Enthusiast

Hi all,

 

I want make sure, in my data all polylines are connected at their ends exactly.

 

As my first step i am iterating through each polyline in drawing.

I am not sure how to check at each end of polyline is it connected to any other polyline or not?

 

Can any one help me how can i do this in .net?

 

Thanks,

Kumar.

0 Likes
997 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

Calculate the distance between endpoints. If it's below a certain FaultTolerance than consider it be closed.

Like:


    ' Imports Autodesk.AutoCAD.Geometry
    <CommandMethod("PointDistance")> _
    Public Sub PointDistance()
        Dim my1Point As New Geometry.Point3d(100, 100, 0)
        Dim my2Point As New Geometry.Point3d(100, 101, 0)

        If my1Point.Equals(my2Point) Then
            Debug.WriteLine("Same point")
        Else
            Debug.WriteLine("Distance=" & my1Point.DistanceTo(my2Point).ToString)
        End If

    End Sub

 

 

0 Likes
Message 3 of 4

giskumar
Enthusiast
Enthusiast

Thanks for the reply,

 

I also want to check a street centerline network, in which each polyline to be snapped at any one end of the other polyline. Hence polylines are not closed ones and at the same time they are connected to each other.

 

Thanks,

Kumar.

0 Likes
Message 4 of 4

giskumar
Enthusiast
Enthusiast

Hi all,

 

The following is the code i have written for snap check between the polylines. Any suggesions to improve please let me know.

 

[CommandMethod("Snapcheck")]
        public static void Snapcheck()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Transaction tr = db.TransactionManager.StartTransaction();
            Editor ed = doc.Editor;
            
            using (tr)
            {
                TypedValue[] tpval = new TypedValue[1];
                tpval.SetValue(new TypedValue((int)DxfCode.Start, "LWPOLYLINE"), 0);
                SelectionFilter fltr = new SelectionFilter(tpval);
                PromptSelectionResult sel = ed.SelectAll(fltr);
                if (sel.Status == PromptStatus.OK)
                {
                    SelectionSet ss = sel.Value;
                    foreach (SelectedObject ent in ss)
                    {
                        DBObject obj = tr.GetObject(ent.ObjectId, OpenMode.ForRead);
                        Polyline objpl = obj as Polyline;
                        if (chksnp(objpl.StartPoint) == "false")
                        {
                            errcle(0.5, "Err_Snap", objpl.StartPoint);
                        }
                        if (chksnp(objpl.EndPoint) == "false")
                        {
                            errcle(0.5, "Err_Snap", objpl.EndPoint);
                        }
                        
                    }
                }
                
                tr.Commit();
            }
        }

 

public static string chksnp(Point3d pnt)
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Transaction tr = db.TransactionManager.StartTransaction();
            Editor ed = doc.Editor;
            string snp="false";
            using (tr)
            {
                //Point3d pnt = ln.StartPoint;
                //double pnt = ln.StartPoint.X;
                //double pnt1 = ln.StartPoint.Y;
                TypedValue[] tpval = new TypedValue[1];
                tpval.SetValue(new TypedValue(10, pnt), 0);
                SelectionFilter fltr = new SelectionFilter(tpval);
                PromptSelectionResult sel1 = ed.SelectAll(fltr);
                if (sel1.Status == PromptStatus.OK)
                {
                    SelectionSet ss1 = sel1.Value;
                 
                    if (ss1.Count > 1)
                    {
                        snp = "true";
                    }
                    
                }
            }
            return snp;
        }

 

public static void errcle(double rad, string lay, Point3d cnpt)
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            Transaction tr = db.TransactionManager.StartTransaction();
            using (tr)
            {
                BlockTable blktb = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord blktr = tr.GetObject(blktb[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                Circle cr = new Circle();
                cr.SetDatabaseDefaults();
                cr.Radius = rad;
                cr.Layer = lay;
                cr.Center = cnpt;
                blktr.AppendEntity(cr);
                tr.AddNewlyCreatedDBObject(cr, true);
                tr.Commit();
            }
        }

 

0 Likes