Any way to get points used in GetSelection?

Any way to get points used in GetSelection?

deltacadd
Contributor Contributor
2,723 Views
4 Replies
Message 1 of 5

Any way to get points used in GetSelection?

deltacadd
Contributor
Contributor

Is there any way to retrieve the list of points used for selecting objects when the Editor.GetSelection() method is run?

 

What I want is something like this:

 

Command: MyCommand

Select objects: WP

First polygon point: <Point picked>

Specify endpoint of line or [Undo]: <Point picked>

Specify endpoint of line or [Undo]: <Point picked>

...

Specify endpoint of line or [Undo]: <ENTER>

 

The list of points is: <x,y>,<x,y>,<x,y>,<x,y>

 

Any help is much appreciated.

0 Likes
2,724 Views
4 Replies
Replies (4)
Message 2 of 5

deltacadd
Contributor
Contributor

Never mind, I figured it out myself. Here is the code:

 

  class CommandShowPoints
  {
    Point3dCollection m_pts = new Point3dCollection();
    public CommandShowPoints()
    {
      Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
      PromptSelectionOptions pso = new PromptSelectionOptions();
      ed.PointMonitor += ed_PointMonitor;
      PromptSelectionResult psr = ed.GetSelection();
      ed.PointMonitor -= ed_PointMonitor;
      if (psr.Status == PromptStatus.Cancel) return;

ed.WriteMessage("\nList of picked points\n"); foreach (Point3d pt in m_pts) { ed.WriteMessage(string.Format("\n{0}", pt)); } } void ed_PointMonitor(object sender, PointMonitorEventArgs e) { Point3d ptLast = e.Context.LastPoint;
if ((ptLast != Point3d.Origin) && (m_pts.Contains(e.Context.LastPoint) == false))
{
m_pts.Add(e.Context.LastPoint);
} } }

 

Now, is there any way to know if the user select a "Window", "Crossing", "WindowPolygon" etc for the selection? I am not interested in querying the entities that are in the selection set, using the "SelectedObject.SelectionMethod", since the window /  crossing / whatever, may not result in a SelectionSet at all.

0 Likes
Message 3 of 5

SENL1362
Advisor
Advisor

The following sample evaluate the Selection details, inclusive the Picked Points. No need for Point monitor

 

        [CommandMethod("TestSelection")]
        public static void TestSelection()
        {
            Document doc = null;
            Database db = null;
            Editor ed = null;

            try
            {
                doc = AcadApp.DocumentManager.MdiActiveDocument;
                if (doc == null)
                    throw new System.Exception("\n Drawing Document required");
                db = doc.Database;
                ed = doc.Editor;

                //Select Objects, use ed.GetSelection to benefit from Window/Crossing selection visual feedback
                PromptSelectionOptions pso = new PromptSelectionOptions();
                pso.MessageForAdding = "Select  Objects";
                pso.SingleOnly = false;
                PromptSelectionResult psr = ed.GetSelection(pso);
                if (psr.Status != PromptStatus.OK)
                    return;

                SelectionSetDelayMarshalled ssMarshal = (SelectionSetDelayMarshalled)psr.Value;
                AdsName name = ssMarshal.Name;
                var selObjIds = ssMarshal.GetObjectIds();
                ed.WriteMessage("\n {0} Objects selected", selObjIds.Length);
                for (int i = 0; i < selObjIds.Length; i++)
                    ed.WriteMessage("\n\t [{0}]: {1} ({2})", i, selObjIds[i].ObjectClass.DxfName, selObjIds[i].Handle);

                SelectionSet selSet = (SelectionSet)ssMarshal;
                ed.WriteMessage("\n {0} Selections in SelectionSet", selSet.Count);

                foreach (SelectedObject ssItem in selSet)
                {
                    ed.WriteMessage("\n\t {0} Selected: {1} ({2})", Enum.GetName(typeof(SelectionMethod), ssItem.SelectionMethod), ssItem.ObjectId.ObjectClass.DxfName, ssItem.ObjectId.Handle);
                    switch (ssItem.SelectionMethod)
                    {
                        case SelectionMethod.PickPoint:
                            PickPointSelectedObject ppSelObj = ssItem as PickPointSelectedObject;
                            Point3d pickedPoint = ppSelObj.PickPoint.PointOnLine;
                            ed.WriteMessage("\n\t\t Selected at: {0}", pickedPoint.ToString());
                            break;

                        case SelectionMethod.Crossing:
                            CrossingOrWindowSelectedObject crossSelObj = ssItem as CrossingOrWindowSelectedObject;
                            PickPointDescriptor[] crossSelPickedPoints = crossSelObj.GetPickPoints();
                            ed.WriteMessage("\n\t\t Crossing at: {0}..{1}", crossSelPickedPoints[0].PointOnLine.ToString(), crossSelPickedPoints[1].PointOnLine.ToString());
                            break;

                        case SelectionMethod.Window:
                            CrossingOrWindowSelectedObject windSelObj = ssItem as CrossingOrWindowSelectedObject;
                            PickPointDescriptor[] winSelPickedPoints = windSelObj.GetPickPoints();
                            ed.WriteMessage("\n\t\t Window at: {0}..{1}", winSelPickedPoints[0].PointOnLine.ToString(), winSelPickedPoints[1].PointOnLine.ToString());
                            break;

                    }
                }
            }
            catch (System.Exception ex)
            {
                if (ed != null)
                    ed.WriteMessage(ex.Message);
                else
                    System.Windows.Forms.MessageBox.Show(ex.Message,
                                "TestSelection",
                                System.Windows.Forms.MessageBoxButtons.OK,
                                System.Windows.Forms.MessageBoxIcon.Error);
            }
        }
Message 4 of 5

deltacadd
Contributor
Contributor

Not sure why, but running the above code shows the last two points for all the entities, if I have selected say a Window Polygon. See example below:

 

FAP.jpg

 

Output:

 

Command: tss

Select  Objects: wp

First polygon point:
Specify endpoint of line or [Undo]:
Specify endpoint of line or [Undo]:
Specify endpoint of line or [Undo]:
Specify endpoint of line or [Undo]:
Specify endpoint of line or [Undo]:
Specify endpoint of line or [Undo]:
12 found

Select  Objects:

 12 Objects selected
 12 Selections in SelectionSet
Window at: 
(1886.16856979758,755.163512841775,0)..(1888.90531905888,952.047645899205,0)
Window at: 
(1886.16856979758,755.163512841775,0)..(1888.90531905888,952.047645899205,0)
Window at: 
(1886.16856979758,755.163512841775,0)..(1888.90531905888,952.047645899205,0)
Window at: 
(1886.16856979758,755.163512841775,0)..(1888.90531905888,952.047645899205,0)
Window at: 
(1886.16856979758,755.163512841775,0)..(1888.90531905888,952.047645899205,0)
Window at: 
(1886.16856979758,755.163512841775,0)..(1888.90531905888,952.047645899205,0)
Window at: 
(1886.16856979758,755.163512841775,0)..(1888.90531905888,952.047645899205,0)
Window at: 
(1886.16856979758,755.163512841775,0)..(1888.90531905888,952.047645899205,0)
Window at: 
(1886.16856979758,755.163512841775,0)..(1888.90531905888,952.047645899205,0)
Window at: 
(1886.16856979758,755.163512841775,0)..(1888.90531905888,952.047645899205,0)
Window at: 
(1886.16856979758,755.163512841775,0)..(1888.90531905888,952.047645899205,0)
Window at: 
(1886.16856979758,755.163512841775,0)..(1888.90531905888,952.047645899205,0)

 

Except for commenting the additional WriteMessages, no other change to the code you have supplied. Any idea why this is happening?

0 Likes
Message 5 of 5

SENL1362
Advisor
Advisor

The sample assumed rectangular window (or crossing) selections only. For polygone selections use this slightly modified code.

 

                           ...
PickPointDescriptor[] crossSelPickedPoints = crossSelObj.GetPickPoints(); if (crossSelPickedPoints != null) { for (int i = 0; i < crossSelPickedPoints.Length;i++ ) ed.WriteMessage("\n\t\t Crossing at[{0}]: {1}", i,crossSelPickedPoints[i].PointOnLine.ToString()); } } break; case SelectionMethod.Window: CrossingOrWindowSelectedObject windSelObj = ssItem as CrossingOrWindowSelectedObject; PickPointDescriptor[] winSelPickedPoints = windSelObj.GetPickPoints(); if (winSelPickedPoints != null) { for (int i = 0; i < winSelPickedPoints.Length; i++) ed.WriteMessage("\n\t\t Window at[{0}]: {1}", i, winSelPickedPoints[i].PointOnLine.ToString()); } break;
...
0 Likes