欢迎加我的QQ群:193522571,一起来讨论、交流!

Linq对对象进行范围排序

ObjectIdCollection ids = STools.GetSelection();
            if (ids.Count == 0) return;

            using (Transaction trans = doc.TransactionManager.StartTransaction())
            {
                List<DBText> sDBTxt = new List<DBText>();
                foreach (ObjectId id in ids)
                {
                    DBText sT = trans.GetObject(id, OpenMode.ForWrite) as DBText;
                    sDBTxt.Add(sT);
                }

        //按x升序排列,按y值降序排列,可以先排序
                var q0 = from e in sDBTxt
                         orderby e.Position.X
                         orderby e.Position.Y descending
                         select e;
        
        //方法2,推荐
                var q1 = sDBTxt.Where(p => p.Position.Y < 658 && p.Position.Y > 150);

                ed.WriteMessage("\n取y坐标值 < 658 且 > 150 的值");
                foreach (DBText st in q1)
                {
                    ed.WriteMessage("\nText:{0,-10}Y:{1,-20}", st.TextString, st.Position.Y);
                }

posted @ 2014-07-07 07:42  swtool  阅读(479)  评论(0编辑  收藏  举报
欢迎加我的QQ群:193522571,一起来讨论、交流!