Select to view content in your preferred language

Arcpy adding selection layer to map adds all features, not just selection

213
1
03-14-2024 04:40 PM
Scosh
by
New Contributor II

Arcpy seems to be adding all features to a map, when I only tell it to add the selection layer. Any ideas what I can do to keep the filter on it? I am running the script from a custom toolbox in an active session.

selection = arcpy.management.SelectLayerByAttribute(layer, 'NEW_SELECTION', "OBJECTID IN {}".format(ready_to_delete))
selection_layer = arcpy.management.MakeFeatureLayer(selection[0]) #### 9 features
m.addLayer(selection_layer[0]) #### adds all 16 features for some reason


Scosh_1-1710459627482.png

 

 

1 Reply
DanPatterson
MVP Esteemed Contributor

Make Feature Layer (Data Management)—ArcGIS Pro | Documentation

If the Input Features parameter value is a layer, the input's symbology, selection, and definition query will be transferred to the output layer

Are there 16 features, but only 9 selected?  I don't see anything about makefeaturelayer removing those that aren't in a selection.  Even SaveToLayerFile preserves selections without feature truncation

 - If the input layer has a selection applied to it, the output layer file will maintain this selection.

CopyFeatures, however truncates those not selected

If the input is a layer and has a selection, only the selected features are copied to the output feature class.

 


... sort of retired...
0 Kudos