ArcGIS Pro 3.1 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / Snapping Class / SetLayerSnapModes Method / SetLayerSnapModes(Layer,LayerSnapModes) Method
The layer to set the snap mode on.
A LayerSnapModes object obtained from GetLayerSnapModes or a new instance of.
Example

In This Topic
    SetLayerSnapModes(Layer,LayerSnapModes) Method
    In This Topic
    Sets the snap modes for a layer.
    Syntax
    public static void SetLayerSnapModes( 
       Layer layer,
       LayerSnapModes modes
    )
    Public Overloads Shared Sub SetLayerSnapModes( _
       ByVal layer As Layer, _
       ByVal modes As LayerSnapModes _
    ) 

    Parameters

    layer
    The layer to set the snap mode on.
    modes
    A LayerSnapModes object obtained from GetLayerSnapModes or a new instance of.
    Remarks
    Snap modes can be set for a layer by either obtaining and modifying the existing snap modes with GetLayerSnapModes or by creating a new instance of LayerSnapModes and setting its properties then setting on the layer with this method.
    Example
    Configure Snapping - LayerSnapModes
    layerList = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>();
    
    // configure by layer
    foreach (var layer in layerList)
    {
      // find the state of the snapModes for the layer
      var lsm = ArcGIS.Desktop.Mapping.Snapping.GetLayerSnapModes(layer);
      bool vertexOn = lsm.Vertex;
      // or use 
      vertexOn = lsm.GetSnapMode(SnapMode.Vertex);
    
      bool edgeOn = lsm.Edge;
      // or use 
      edgeOn = lsm.GetSnapMode(SnapMode.Edge);
    
      bool endOn = lsm.End;
      // or use 
      endOn = lsm.GetSnapMode(SnapMode.End);
    
      // update a few snapModes 
      //   turn Vertex off
      lsm.SetSnapMode(SnapMode.Vertex, false);
      // intersections on
      lsm.SetSnapMode(SnapMode.Intersection, true);
    
      // and set back to the layer
      ArcGIS.Desktop.Mapping.Snapping.SetLayerSnapModes(layer, lsm);
    
    
      // assign a single snap mode at once
      ArcGIS.Desktop.Mapping.Snapping.SetLayerSnapModes(layer, SnapMode.Vertex, false);
    
    
      // turn ALL snapModes on
      ArcGIS.Desktop.Mapping.Snapping.SetLayerSnapModes(layer, true);
      // turn ALL snapModes off
      ArcGIS.Desktop.Mapping.Snapping.SetLayerSnapModes(layer, false);
    }
    
    
    // configure for a set of layers
    
    // set Vertex, edge, end on for a set of layers, other snapModes false
    var vee = new LayerSnapModes(false);
    vee.Vertex = true;
    vee.Edge = true;
    vee.End = true;
    ArcGIS.Desktop.Mapping.Snapping.SetLayerSnapModes(layerList, vee);
    
    
    // ensure intersection is on for a set of layers without changing any other snapModes
    
    // get the layer snapModes for the set of layers
    var dictLSM = ArcGIS.Desktop.Mapping.Snapping.GetLayerSnapModes(layerList);
    foreach (var layer in dictLSM.Keys)
    {
      var lsm = dictLSM[layer];
      lsm.Intersection = true;
    }
    ArcGIS.Desktop.Mapping.Snapping.SetLayerSnapModes(dictLSM);
    
    
    // set all snapModes off for a list of layers
    ArcGIS.Desktop.Mapping.Snapping.SetLayerSnapModes(layerList, false);
    
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.0 or higher.
    See Also