.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to get the distance between two points with C#

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
sonny3g
3429 Views, 4 Replies

How to get the distance between two points with C#

The problem is that a user needs to select a block the select a point on that block where he wants a leader to be placed.  I need to be able to tell how far from the block insertion point is the point where he wants the leader to be placed regardless of the rotation of the block or the orientation of the UCS. 

 

I have been chasing my tail on this for two days and I just don't know how to do this.  Anyone got a suggestion?  All help is appreciated.

 

Sonny

 

Scott G. Sawdy
scott.sawdy@bluecoyotecad.com
4 REPLIES 4
Message 2 of 5
_gile
in reply to: sonny3g

Hi,

 

You simply need to get the BlockReference.Position which is always WCS defined and transform the point returned by PromptPointResult.Value to WCS coordinates because it's always UCS defined.

 

            var ed = Application.DocumentManager.MdiActiveDocument.Editor;
            var peo = new PromptEntityOptions("\nSelect block: ");
            peo.SetRejectMessage("\nMust be a block.");
            peo.AddAllowedClass(typeof(BlockReference), true);
            var per = ed.GetEntity(peo);
            if (per.Status == PromptStatus.OK)
            {
                var ppr = ed.GetPoint("\nSpecify a point: ");
                if (ppr.Status == PromptStatus.OK)
                {
                    dynamic br = per.ObjectId;
                    var position = br.Position;
                    var point = ppr.Value.TransformBy(ed.CurrentUserCoordinateSystem);
                    var distance = point.DistanceTo(position);
                    ed.WriteMessage("\nDistance = {0}", distance);
                }
            }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 5
kdub_nz
in reply to: sonny3g

Nice example Gilles.

 

Sonny,

Because the example uses dynamic ;

Important: When working with DLR and C#, you will need to reference the Microsoft.CSharp library.

 


https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-NET/files/GUI...

 

 

 

 


// Called Kerry in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect.

class keyThumper<T> : Lazy<T>;      another  Swamper

Message 4 of 5
sonny3g
in reply to: kdub_nz

Thanks _kdub,

I will take some time out to read through the article in the link you provided.

 

sonny

Scott G. Sawdy
scott.sawdy@bluecoyotecad.com
Message 5 of 5
sonny3g
in reply to: _gile

Thanks Giles, as always you come through with a solution!

 

Sonny

Scott G. Sawdy
scott.sawdy@bluecoyotecad.com

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report