Author Topic: VB.Net method of selecting by fence and/or window  (Read 2979 times)

0 Members and 1 Guest are viewing this topic.

cannorth

  • Guest
VB.Net method of selecting by fence and/or window
« on: October 05, 2011, 04:10:47 PM »
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

huiz

  • Swamp Rat
  • Posts: 917
  • Certified Prof C3D
Re: VB.Net method of selecting by fence and/or window
« Reply #1 on: October 06, 2011, 02:34:06 AM »
When selecting on the screen people can use selection options like F or CP by themself. You can put that information in the PromptSelectionOptions.MessageForAdding.
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

fixo

  • Guest
Re: VB.Net method of selecting by fence and/or window
« Reply #2 on: October 06, 2011, 04:59:14 AM »
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

Change to your suit, this one is from working project,
don't remember how it works :)

Code: [Select]
        #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
To convert, try this:
http://converter.telerik.com/

~'J'~