minimum distance between two entities

minimum distance between two entities

Anonymous
Not applicable
2,523 Views
5 Replies
Message 1 of 6

minimum distance between two entities

Anonymous
Not applicable

Hello,

 

How can we find minimum distance between the entities (entity can be a polyline, circle, arc, etc).

0 Likes
Accepted solutions (1)
2,524 Views
5 Replies
Replies (5)
Message 2 of 6

_gile
Consultant
Consultant

Hi,

 

If the entities derive from Curve, you can get the corresponding Curve3d object with the Curve.GetGeCurve() method.

The Curve3d type has a Curve3d.GetDistanceTo(Curve3d) method which returns the minimum distance beween the curves.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 6

Anonymous
Not applicable

Sir,

thank u for reply.

 if there are two entities close to each other( closed entity having four sides ), then how can i get minimum distance between them.?

0 Likes
Message 4 of 6

_gile
Consultant
Consultant
Accepted solution

Here's a testing command using the process I described upper (requires A2013+ for the GetGeCurve() method).

 

        [CommandMethod("MinDist")]
        public void GetMinimumDistance()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;

            var options = new PromptEntityOptions("\nSelect first object: ");
            options.SetRejectMessage("Must be a curve.");
            options.AddAllowedClass(typeof(Curve), false);
            var result = ed.GetEntity(options);
            if (result.Status != PromptStatus.OK)
                return;
            var id1 = result.ObjectId;

            options.Message = "\nSelect second object: ";
            result = ed.GetEntity(options);
            if (result.Status != PromptStatus.OK)
                return;
            var id2 = result.ObjectId;

            using (var tr = db.TransactionManager.StartTransaction())
            {
                var curve1 = (Curve)tr.GetObject(id1, OpenMode.ForRead);
                var curve2 = (Curve)tr.GetObject(id2, OpenMode.ForRead);
                var distance = curve1.GetGeCurve().GetDistanceTo(curve2.GetGeCurve());
                ed.WriteMessage("\nDistance = {0}", distance);
                tr.Commit();
            }
        }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 5 of 6

Anonymous
Not applicable
thanks u very much..
0 Likes
Message 6 of 6

Anonymous
Not applicable

Hello Gilles,

 

May I know how to use this? I'm very new to programming. 

 

Do you have any screen shots for this?

 

Thank you very much in advance.

 

 

 

0 Likes