标签:
public static class Class2 { public static ObjectId[] fun(Point3d point) { Database db = HostApplicationServices.WorkingDatabase; Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; Point3dCollection points = new Point3dCollection(); List<string> wenben = new List<string>(); List<double> distance = new List<double>(); ObjectId[] s = new ObjectId[2]; ObjectIdCollection textids = new ObjectIdCollection(); TypedValue[] values = new TypedValue[] { new TypedValue((int)DxfCode.LayerName,"TK"), new TypedValue((int)DxfCode.Start,"TEXT") }; SelectionFilter selfilter = new SelectionFilter(values); PromptSelectionResult psr = ed.SelectAll(selfilter); if (psr.Status == PromptStatus.OK) { SelectionSet ss = psr.Value; using (Transaction trans = db.TransactionManager.StartTransaction()) { foreach (ObjectId id in ss.GetObjectIds()) { DBText mytext = trans.GetObject(id, OpenMode.ForRead) as DBText; if (mytext != null) { points.Add(mytext.Position); wenben.Add(mytext.TextString); // mytext.TextString = ""; textids.Add(id); distance.Add(point.DistanceTo(mytext.Position)); } } trans.Commit(); } } else { ed.WriteMessage("错误"); return s; } ////冒泡 double temp = 0; string wenbentemp = ""; ObjectId tempid = new ObjectId(); for (int i = distance.Count; i > 0; i--) { for (int j = 0; j < i - 1; j++) { if (distance[j] > distance[j + 1]) { temp = distance[j]; wenbentemp = wenben[j]; tempid = textids[j]; distance[j] = distance[j + 1]; wenben[j] = wenben[j + 1]; textids[j] = textids[j + 1]; distance[j + 1] = temp; wenben[j + 1] = wenbentemp; textids[j + 1] = tempid; } } } /////冒泡结束 s[0] = textids[0]; s[1] = textids[1]; return s; } }
学习点:找到与制定点最近的2个实体的ID;冒泡排序,选择集;以及基本的CAD二次开发过程
标签:
原文地址:http://www.cnblogs.com/w-lumi/p/5701028.html