ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / FeatureLayer Class / SetSnappable Method
A boolean to toggle snappability.
Example

In This Topic
    SetSnappable Method (FeatureLayer)
    In This Topic
    Enables or disables snapping on the feature layer. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public void SetSnappable( 
       bool isSnappable
    )
    Public Sub SetSnappable( _
       ByVal isSnappable As Boolean _
    ) 

    Parameters

    isSnappable
    A boolean to toggle snappability.
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Example
    Configure Snapping - Layer Snappability
    // is the layer snappable?
    bool isSnappable = fLayer.IsSnappable;
    
    // set snappability for a specific layer - needs to run on the MCT
    await QueuedTask.Run(() =>
    {
      // use an extension method
      fLayer.SetSnappable(true);
    
      // or use the CIM directly
      //var layerDef = fLayer.GetDefinition() as ArcGIS.Core.CIM.CIMGeoFeatureLayerBase;
      //layerDef.Snappable = true;
      //fLayer.SetDefinition(layerDef);
    });
    
    
    // turn all layers snappability off
    layerList = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>();
    await QueuedTask.Run(() =>
    {
      foreach (var layer in layerList)
      {
        layer.SetSnappable(false);
      }
    });
    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) { 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
    Change layer visibility, editability, snappability
    if (!layer.IsVisible)
      layer.SetVisibility(true);
    
    if (layer is FeatureLayer featureLayer)
    {
      if (!featureLayer.IsEditable)
        featureLayer.SetEditable(true);
    
      if (!featureLayer.IsSnappable)
        featureLayer.SetSnappable(true);
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also