Skip to content

Instantly share code, notes, and snippets.

@stdavis
Created Dec 15, 2017
Embed
What would you like to do?
SetOnUndone & SetOnRedone - What am I doing wrong?
private void AddSelectedToTemp()
{
QueuedTask.Run(() =>
{
using (FeatureClass tempSegsFC = TempSegmentsLayer.GetFeatureClass())
using (RowCursor segmentsCursor = SegmentsLayer.GetSelection().Search((QueryFilter)null, false))
{
EditOperation operation = new EditOperation();
operation.Name = "add selected to temp segments";
bool newPartCreated = false;
operation.Callback(context =>
{
while (segmentsCursor.MoveNext())
{
string id = GetUSNGID_Line(segmentsCursor.Current);
RowBuffer tempRowBuf = CopyRowValues(segmentsCursor.Current, tempSegsFC);
tempRowBuf["USNG_SEG"] = id;
if (tempSegmentIDs.Contains(id))
{
currentPart++;
tempSegmentIDs.Clear();
newPartCreated = true;
}
tempSegmentIDs.Add(id);
tempRowBuf["RoutePart"] = currentPart;
tempSegsFC.CreateRow(tempRowBuf);
tempRowBuf.Dispose();
}
context.Invalidate(tempSegsFC);
}, tempSegsFC);
if (newPartCreated)
{
// NOT WORKING ref: https://community.esri.com/message/733381-re-examples-for-setonundone-setonredone-setoncomitted?commentID=733381#comment-733381
operation.SetOnUndone(() =>
{
currentPart--;
});
operation.SetOnRedone(() =>
{
currentPart++;
});
}
bool success = operation.Execute();
if (success)
{
SegmentsLayer.ClearSelection();
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment