ArcGIS Pro 3.7 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 Sub SetSnappable( _
       ByVal isSnappable As Boolean _
    ) 
    public void SetSnappable( 
       bool isSnappable
    )

    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
    var featureLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault();
    // is the layer snappable?
    bool isSnappable = featureLayer.IsSnappable;
    // set snappability for a specific layer - needs to run on the MCT
    await QueuedTask.Run(() =>
    {
      // use an extension method
      featureLayer.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
    var 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
    Snapping.IsEnabled = true;
    
    // turn all application snapModes off
    Snapping.SetSnapModes(null);
    
    // set application snapMode vertex on 
    Snapping.SetSnapMode(SnapMode.Vertex, true);
    
    // ensure layer snapping is on
    await QueuedTask.Run(() =>
    {
      featureLayer.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(featureLayer, vertexOnly);
    Snapping.SetLayerSnapModes(dict, true);  // true = reset other layers
    Change layer visibility, editability, snappability
    {
        if (!layer.IsVisible)
            layer.SetVisibility(true);
    
        if (layer is FeatureLayer featureLayerToChange)
        {
            if (!featureLayer.IsEditable)
                featureLayer.SetEditable(true);
    
            if (!featureLayer.IsSnappable)
                featureLayer.SetSnappable(true);
        }
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also