Prod.: Engine, ver.: 6, ID: 60001531, HowTo : How can I select some entities with a polyline and delete all other entities

HowTo : How can I select some entities with a polyline and delete all other entities

Article60001531
TypeHowTo
ProductEngine
Version6
Date Added11/3/2011
Submitted byLuca Mancusi
Keywords

Subject

How can I select some entities with a polyline and delete all other entities

Summary

I want to make the following function: drawing a polyline, I would like to keep all the objects that are inside the polyline and eliminate all those outside.

Solution

You can do it with a code like :
VectorDraw.Professional.vdObjects.vdDocument vdDoc = vdFramedControl1.BaseControl.ActiveDocument;
vdSelection sel = new vdSelection();
sel.SetUnRegisterDocument(vdDoc);
sel.Name = "ents";
vdDoc.Prompt("Select Entities to keep: ");
gPoints pts = vdDoc.ActionUtility.getUserPerigramViewCS(true, true);
vdDoc.Prompt(null);
sel.Select(VectorDraw.Render.RenderSelect.SelectingMode.CrossingWindowPolygon, pts); // or WindowPolygon if you like entities to be completely inside the polygon
if (sel.Count > 0)
{
    MessageBox.Show("Keep " + sel.Count.ToString() +" entities."); // the selection now has the entities you want to keep
    vdDoc.CommandAction.CmdErase("ALL"); // delete all including the entities to keep
    foreach (VectorDraw.Professional.vdPrimaries.vdFigure item in sel)
    {
        item.Deleted = false; // but set the previously selected entities as not deleted
    }
    vdDoc.Redraw(true);
}
else
{
    MessageBox.Show("Nothing selected, nothing deleted."); 
}