Responding to changes in the edit sketch


Summary
This topic describes the events the editor provides that allow you to listen and respond to changes in the edit sketch, which is often used to manipulate new or existing features.


Edit sketch geometry updates

Updates to the edit sketch geometry occur frequently during the course of an operation. You may want to listen to these events if, for example, you're performing validation logic each time the sketch changes (such as minimum number of points or certain segment types) or if you're updating the display.
The editor supports a number of events to listen to changes in the edit sketch. The most commonly used event is IEditEvents.OnSketchModified. This event is fired whenever the geometry of the edit sketch changes, such as when adding a point via IEditSketch.AddPoint or when the geometry is altered or updated via IEditSketch.Geometry.
Because of the generic nature of this event, OnSketchModified is often fired frequently. Ensure your code is not performing potentially expensive operations when listening and responding to this event.
There are more specific events related to changes in the edit sketch geometry. Three methods on the IEditEvents2 interface (OnVertexAdded, OnVertexDeleted, and OnVertexMoved) are fired by corresponding methods on IEditSketch2 (VertexAdded, VertexDeleted, and VertexMoved). When the IEditSketch2 functions fire event notifications (when vertices are added, modified, or deleted), the affected point geometry is passed to the listeners.
ISketchOperation2.Finish allows you to specify this information while, internally, the appropriate method on IEditSketch2 is fired. Because ISketchOperation2.Finish fires these methods automatically, you should not use the vertex-specific methods on IEditSketch2 directly.
Clients interested in responding to changes in the edit sketch geometry always receive the OnSketchModified event; however, this event does not provide detailed information about the change that was made to the sketch geometry.
See Edit event listener to better understand which editing events are fired during various sketch operations.
When the sketch is finished, another event is fired. At this point, the sketch is applied to the editor's current edit task, which utilizes the sketch geometry to complete a given operation.

Edit sketch display

To determine when display-based actions related to the sketch are occurring, use IEditEvents.AfterDrawSketch and IEditEvents3.BeforeDrawSketch. Both of these events are fired frequently, usually resulting from changes to the edit sketch geometry or when the display is refreshed.
Unless you're changing the edit sketch display behavior, most customizations do not need to respond to these events.

Edit sketch selection events

The editor supports the selection of vertices in the edit sketch. This selection usually represents the set of vertices to which an action will be applied, such as deleting, moving, or calculating vertex (M and Z) attributes.
If your customization depends on the sketch selection to meet certain criteria (for example, number of vertices selected, or only the from-point of a polyline sketch), listen for IEditEvents5.OnVertexSelectionChanged. In your event handler, you can then check the selection count via IEditSketch3.SelectedVertexCount. Alternatively, if the selection is invalid, you can clear the selected vertices before proceeding using IEditSketch3.ClearSelectedVertices.


See Also:

Working with editing events
Sample: Edit event listener




To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
ArcGIS for Desktop Advanced ArcGIS for Desktop Advanced
ArcGIS for Desktop Standard ArcGIS for Desktop Standard
ArcGIS for Desktop Basic ArcGIS for Desktop Basic