selected polyline direction

selected polyline direction

essam-salah
Advisor Advisor
1,042 Views
1 Reply
Message 1 of 2

selected polyline direction

essam-salah
Advisor
Advisor

hi

i'm trying to write a command using c# based on a selected polyline,
the problem is to get the direction of polyline,
i want to get the location of the point at which the user picked the polyline so i can decide the direction somehow,
or im wondering if there is a way to do something as _AeccCreateAlignmentEntities does (atteched photo),
any help will be appreciated.

 

#region Asking the user to accept the direction or reverse;

                    var reverseOption = new PromptKeywordOptions("\nPress Enter to accept the direction or ");
                    reverseOption.Keywords.Add("Reverse");
                    reverseOption.AllowNone = true;
                    var reverseRes = editor.GetKeywords(reverseOption);

                    if (reverseRes.Status == PromptStatus.None)
                    {
                        editor.WriteMessage($"\n You accepted the direction");
                    }
                    else if (reverseRes.StringResult == "Reverse")
                    {
                        editor.WriteMessage($"\ndirection has reversed ({reverseRes.Status})");
// TO DO } else { return; } #endregion
0 Likes
Accepted solutions (1)
1,043 Views
1 Reply
Reply (1)
Message 2 of 2

Jeff_M
Consultant
Consultant
Accepted solution

Something like this:

            var doc = Application.DocumentManager.MdiActiveDocument;
            var ed = doc.Editor;
            var db = doc.Database;
            var prmptOpt = new PromptEntityOptions("\nSelect polyline:");
            prmptOpt.SetRejectMessage("...not a polyline, try again.");
            prmptOpt.AddAllowedClass(typeof(Polyline), true);
            var selection = ed.GetEntity(prmptOpt);
            if (selection.Status != PromptStatus.OK)
                return;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                var pline = (Polyline)tr.GetObject(selection.ObjectId, OpenMode.ForRead);
                var ptOnPline = pline.GetClosestPointTo(selection.PickedPoint,false);//picked point may not lie exactly on the pline
                var direction = pline.GetFirstDerivative(ptOnPline).AngleOnPlane(new Plane(new Point3d(0, 0, 0), Vector3d.ZAxis)); //this will be the direction of te pline at that point
                //place call to code for TransientGraphics arrow to show the direction
                //place code to ask user to verify direction OK or reverse
                //if reverse, reverse the direction here.
            }
Jeff_M, also a frequent Swamper
EESignature