#AU2013 Wish granted – Delete topo points in elevation range

Kelly asked “Is it possible to delete points within a range of elevation values?”

Yes!


public void deleteTopoPointsByElevation()
{
    Document doc = this.ActiveUIDocument.Document;
    UIDocument uidoc = new UIDocument(doc);

    double min = 20;
    double max = 30;

    TopographySurface topo = doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element)) as TopographySurface;
    IList<XYZ> pointsToDelete = new List<XYZ>();

    foreach (XYZ pt in topo.GetPoints())
    {
        if (pt.Z > min && pt.Z < max)
            pointsToDelete.Add(pt);
    }

    using (TopographyEditScope tes = new TopographyEditScope(doc, "Topo Edit Scope"))
    {
        tes.Start(topo.Id);

            using (Transaction t = new Transaction(doc, "Update Topo"))
            {
                t.Start();
                topo.DeletePoints(pointsToDelete);
                t.Commit();
            }

        tes.Commit(new myFailuresPreprocessor());
    }
}

public class myFailuresPreprocessor : IFailuresPreprocessor
{
    public FailureProcessingResult PreprocessFailures(FailuresAccessor failuresAccessor)
    {
        return FailureProcessingResult.Continue;
    }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s