ArcGIS Pro 3.1 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / Snapping Class / SetSnapMode Method
Example

In This Topic
    SetSnapMode Method (Snapping)
    In This Topic

    Sets the state of a single SnapMode.

    Syntax
    public static void SetSnapMode( 
       SnapMode mode,
       bool value
    )
    Public Shared Sub SetSnapMode( _
       ByVal mode As SnapMode, _
       ByVal value As Boolean _
    ) 

    Parameters

    mode
    value
    Example
    Configure Snapping - Application SnapModes
    // set only Point and Edge snapping modes, clear everything else
    //At 2.x - ArcGIS.Desktop.Mapping.Snapping.SetSnapModes(SnapMode.Point, SnapMode.Edge);
    ArcGIS.Desktop.Mapping.Snapping.SetSnapModes(
      new List<SnapMode>() { SnapMode.Point, SnapMode.Edge });
    
    // clear all snap modes
    //At 2.x - ArcGIS.Desktop.Mapping.Snapping.SetSnapModes();
    ArcGIS.Desktop.Mapping.Snapping.SetSnapModes(null);
    
    
    // set snap modes one at a time
    ArcGIS.Desktop.Mapping.Snapping.SetSnapMode(SnapMode.Edge, true);
    ArcGIS.Desktop.Mapping.Snapping.SetSnapMode(SnapMode.End, true);
    ArcGIS.Desktop.Mapping.Snapping.SetSnapMode(SnapMode.Intersection, true);
    
    // get current snap modes
    var snapModes = ArcGIS.Desktop.Mapping.Snapping.SnapModes;
    
    // get state of a specific snap mode
    bool isOn = ArcGIS.Desktop.Mapping.Snapping.GetSnapMode(SnapMode.Vertex);
    
    Configure Snapping - Combined Example
    // interested in only snapping to the vertices of a specific layer of interest and not the vertices of other layers
    //  all other snapModes should be off.
    
    // snapping must be on
    ArcGIS.Desktop.Mapping.Snapping.IsEnabled = true;
    
    // turn all application snapModes off
    //At 2.x - ArcGIS.Desktop.Mapping.Snapping.SetSnapModes();
    ArcGIS.Desktop.Mapping.Snapping.SetSnapModes(null);
    
    // set application snapMode vertex on 
    ArcGIS.Desktop.Mapping.Snapping.SetSnapMode(SnapMode.Vertex, true);
    
    // ensure layer snapping is on
    await QueuedTask.Run(() =>
    {
      fLayer.SetSnappable(true);
    });
    
    // set vertex snapping only
    var vertexOnly = new LayerSnapModes(false);
    vertexOnly.Vertex = true;
    
    // set vertex only for the specific layer, clearing all others
    var dict = new Dictionary<Layer, LayerSnapModes>();
    dict.Add(fLayer, vertexOnly);
    ArcGIS.Desktop.Mapping.Snapping.SetLayerSnapModes(dict, true);  // true = reset other layers
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.0 or higher.
    See Also