CAD2008的二次开发,有个很奇怪的现象,只要你选择的点集不在当前视图上SelectCrossingPolygon和SelectFence返回结果Status就会为error,所以要获取正确的结果,在操作前最好全屏缩放一下!
小测试:
[CommandMethod("TestPromptSelectionResult")] public void TestPromptSelectionResult() { Point3dCollection pt3dCol = new Point3dCollection(); pt3dCol.Add(new Point3d(486750, 2538400, 0)); pt3dCol.Add(new Point3d(487000, 2538400, 0)); pt3dCol.Add(new Point3d(487000, 2538600, 0)); pt3dCol.Add(new Point3d(486750, 2538600, 0)); pt3dCol.Add(new Point3d(486750, 2538400, 0)); Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; PromptSelectionResult psrss = doc.Editor.SelectFence(pt3dCol); //if (psrss.Status != PromptStatus.OK) MessageBox.Show(psrss.Status.ToString()); Polyline pl = new Polyline(); for (int i = 0; i < pt3dCol.Count; i++) { //添加多段线的顶点 pl.AddVertexAt(i, new Point2d(pt3dCol[i].X, pt3dCol[i].Y), 0, 0, 0); } CadDatabase.AppendToModelSpace(pl, doc.Database); }
最后你只要看到那个多段线,再打入命令TestPromptSelectionResult就会返回OK,个人认为是c#Cad二次开发的一下Bug,求大神打我脸!