0 Members and 1 Guest are viewing this topic.
Hello, Is there a VB.Net method of selecting entities on screen using fence or window. I'm looking for a single method rather than two separate ones.Thanks,cannorth
#region "Selection with using of keywords" [CommandMethod("SelectBy")] public void GetSelectionWithKeywords() { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; try { PromptKeywordOptions pko = new PromptKeywordOptions( "\nChoose a selection method " + "[Window/Fence]: ", "Window Fence" ); pko.Keywords.Default ="Window"; PromptResult prk = ed.GetKeywords(pko); if (prk.Status != PromptStatus.OK) return; string kwd = prk.StringResult; PromptSelectionOptions pso = new PromptSelectionOptions(); pso.MessageForAdding = "\nSelect objects by " + kwd + " selection"; pso.MessageForRemoval = "\nNothing selected, try again..."; if (kwd == "Window") { PromptPointOptions ppo = new PromptPointOptions("\nSpecify a first corner: "); PromptPointResult ppr = ed.GetPoint(ppo); if (ppr.Status != PromptStatus.OK) return; PromptCornerOptions pco = new PromptCornerOptions("\nOther corner: ", ppr.Value); PromptPointResult pcr = ed.GetCorner(pco); if (pcr.Status != PromptStatus.OK) return; Point3d p1 = ppr.Value; Point3d p2 = pcr.Value; if (p1.X == p2.X || p1.Y == p2.Y) { ed.WriteMessage("\nInvalid coordinate specification"); return; } PromptSelectionResult psr= ed.SelectWindow(p1, p2); if (psr.Status == PromptStatus.OK) { ed.WriteMessage("\n{0} object{1} selected.", psr.Value.Count, psr.Value.Count == 1 ? "" : "s" ); } } if (kwd == "Fence") { PromptPointOptions ppo = new PromptPointOptions("\nSpecify a first fence point: "); PromptPointResult ppr = ed.GetPoint(ppo); if (ppr.Status != PromptStatus.OK) return; Point3d p1 = ppr.Value; PromptPointOptions pco = new PromptPointOptions("\nSecond point: "); pco.UseBasePoint = true; pco.BasePoint = p1; pco.UseDashedLine = true; PromptPointResult pcr = ed.GetPoint(pco); if (pcr.Status != PromptStatus.OK) return; Point3d p2 = pcr.Value; if (p1.X == p2.X && p1.Y == p2.Y) { ed.WriteMessage("\nInvalid coordinate specification"); return; } Point3dCollection points = new Point3dCollection(); points.Add(p1); points.Add(p2); PromptSelectionResult psr= ed.SelectFence(points); if (psr.Status == PromptStatus.OK) { ed.WriteMessage( "\n{0} object{1} selected.", psr.Value.Count, psr.Value.Count == 1 ? "" : "s" ); } } } catch (System.Exception ex) { Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(ex.Message + "\n" + ex.StackTrace); } finally { } } #endregion