### Author Topic: order curve by direction  (Read 774 times)

0 Members and 1 Guest are viewing this topic.

#### daboho

• Newt
• Posts: 40 ##### order curve by direction
« on: August 24, 2022, 03:01:51 PM »
i have problem to order curve by direction
problem see green colour with circle not same direction with yellow colour
how to order curve by direction in picture while user select all curve is no problem
but if curve selection by random ,curve not to order
i want order curve by direction vector (direction to X,Y)
finaly i want to get max distance for every curve in group direction
for example in red colour of picture (i want get distance curve 1 to curve 2,curve 3 to curve 4,curve 5 to 6,curve 7 to curve and so on for curve in another group by vector direction
finaly i want to get rank/max of distance for all group
all count of curve in group is EVEN ,i am know a litte to compare curve by step 2 in every group
this is my code how to edit my code to get goal?
Code: [Select]
` [CommandMethod("un")]       public void getMaxdistGroup()       {            var doc = acApp.DocumentManager.MdiActiveDocument;            var db = doc.Database;            var ed = doc.Editor;            var psr = ed.GetSelection();            if (psr.Status != PromptStatus.OK) return;             using (Transaction tr = db.TransactionManager.StartTransaction())             {                    var space = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;                var gr = psr.Value.Cast<SelectedObject>()                         .Select(p => (Curve)tr.GetObject(p.ObjectId, OpenMode.ForRead))                         .GroupBy(cur => new Vector3d(Math.Abs(cur.StartPoint.GetVectorTo(cur.EndPoint).GetNormal().X),                         Math.Abs(cur.StartPoint.GetVectorTo(cur.EndPoint).GetNormal().Y),                         Math.Abs(cur.StartPoint.GetVectorTo(cur.EndPoint).GetNormal().Z)),cur =>cur);                var exten = new Extents3d();                for (int i = 0; i < gr.Count(); i++)                {                    var cols = gr.ElementAt(i);                    //var mylist = new List<Curve>();                    //if(cols.Key.Y == 1)                    //{                    //    mylist = cols.Cast<Curve>().OrderBy(p => p.StartPoint.Y).ThenBy(p=>p.StartPoint.X).ToList();                    //}                    //else if (cols.Key.X == 1)                    //{                    //    mylist = cols.Cast<Curve>().OrderBy(p => p.StartPoint.Y).ThenBy(p => p.StartPoint.X).ToList();                    //}                    ed.WriteMessage(\$"\ncount of group{cols.Count()}\t dan key {cols.Key}");                    int n = 0;                     foreach (var item in cols)                    {                        ed.WriteMessage(\$"\npoint sort {item.StartPoint}");                        item.UpgradeOpen();                        item.ColorIndex = i+1;                        exten.AddExtents(item.GeometricExtents);                        AddMtext(0.3, item.GetPointAtParameter(0.5), (++n).ToString());                    }                }                ed.WriteMessage(\$"\npoint mint {exten.MinPoint}");                tr.Commit();             }            }`