HowTo : Select entities from a point (four methods)
| Article | 60000341 |
| Type | HowTo |
| Product | Engine |
| Version | 6 |
| Date Added | 12/6/2007 |
| Submitted by | VectorDraw |
| Keywords | |
Subject
Select entities from a point (four methods)
Summary
Select entities that are in locked/unlocked layers from a single point.
Solution
In this howto we will use four methods to select entities that might be in locked or unlocked layers from a point that we get using getUserPoint() (this is pt) like :
gPoint pt = vdScrollableControl1.BaseControl.ActiveDocument.ActionUtility.getUserPoint() as gPoint;
and for the Selection Set :
vdSelection selectionSet = null;
selectionSet = vdScrollableControl1.BaseControl.ActiveDocument.Selections.FindName(name);
if (selectionSet == null)
{
selectionSet = vdScrollableControl1.BaseControl.ActiveDocument.Selections.Add(name);
}
gPoint p1 = m_ActiveDoc.World2PixelMatrix.Transform(pt as gPoint);
Method 1: Selection with RenderSelect.SelectingMode.SingleEntitiyPoint
This will get the top-most entity. If this entity is in a locked layer then the returned selectionSet will be empty
// Selection with RenderSelect.SelectingMode.SingleEntitiyPoint
gPoints points = new gPoints();
selectSet.RemoveAll();
points.Add(pt);
selectSet.Select(RenderSelect.SelectingMode.SingleEntitiyPoint, points);
if (selectSet.Count > 0)
{
foreach (vdFigure fig in selectSet)
{
MessageBox.Show("Found figure with Handle " + fig.HandleId.ToString() + " in Layer: " + fig.Layer.Name + " which is locked: " + fig.Layer.Lock.ToString(), "[Select with SingleEntitiyPoint]");
}
}
else
{
MessageBox.Show("No object selected","[Select with SingleEntitiyPoint]");
}
Method 2: Selection with Selection with GetEntityFromPoint
This will get the top-most entity even if this entity is in a locked layer.
// Selection with GetEntityFromPoint
Point location1 = new Point((int)p1.x, (int)p1.y);
vdFigure fig2 = m_ActiveDoc.ActiveLayOut.GetEntityFromPoint(location1, m_ActiveDoc.ActiveLayOut.Render.GlobalProperties.PickSize, false);
if (fig2 != null)
{
MessageBox.Show("Found figure with Handle: " + fig2.HandleId.ToString() + " in Layer: " + fig2.Layer.Name + " which is locked: " + fig2.Layer.Lock.ToString(),"[Select with GetEntityFromPoint]" );
}
else
{
MessageBox.Show("No object selected", "[Select with GetEntityFromPoint]");
}
Method 3: Selection with RenderSelect.SelectingMode.CrossingWindowRectangle and the cursor's PickSize
This will get all the entities in the current point+picksize but not entities at locked layers
// Selection with RenderSelect.SelectingMode.CrossingWindowRectangle and the cursors PickSize
selectSet.RemoveAll();
gPoints points2 = new gPoints();
int size = m_ActiveDoc.ActiveLayOut.Render.GlobalProperties.PickSize;
Point location2 = new Point((int)p1.x-size/2, (int)p1.y-size/2);
Point location3 = new Point((int)p1.x+size/2, (int)p1.y+size/2);
points2.Add(m_ActiveDoc.ActiveLayOut.Render.Pixel2View(location2));
points2.Add(m_ActiveDoc.ActiveLayOut.Render.Pixel2View(location3));
selectSet.Select(RenderSelect.SelectingMode.CrossingWindowRectangle, points2);
if (selectSet.Count > 0)
{
foreach (vdFigure fig in selectSet)
{
MessageBox.Show("Found figure with Handle " + fig.HandleId.ToString() + " in Layer: " + fig.Layer.Name + " which is locked: " + fig.Layer.Lock.ToString(), "[Select with CrossingWindowRectangle & PickSize]");
}
}
else
{
MessageBox.Show("No object selected", "[Select with CrossingWindowRectangle & PickSize]");
}
Method 4: Selection with Selection using Select3D and the cursor's PickSize
This will get all the entities in the current point+picksize even entities in locked layers
// Selection using Select3D and cursor's picksize
Point location4 = new Point((int)p1.x , (int)p1.y );
vdEntities ents = m_ActiveDoc.Select3d(location4, m_ActiveDoc.ActiveLayOut.Render.GlobalProperties.PickSize);
if (ents.Count > 0)
{
foreach (vdFigure fig in ents)
{
MessageBox.Show("Found figure with Handle " + fig.HandleId.ToString() + " in Layer: " + fig.Layer.Name + " which is locked: " + fig.Layer.Lock.ToString(), "[Select with Select3d & PickSize]");
}
}
else
{
MessageBox.Show("No object selected", "[Select with Select3d & PickSize]");
}