I use "Copy Features" tool to make a layer from selection. It's crucial that I check for a selection first or it will copy the whole layer. Please help me with that. Thank you!
And something like this should also work:
selection = arcpy.SelectLayerByAttribute_management(layer, "NEW_SELECTION", where_clause="Field = 'Something'")result = arcpy.GetCount_management(selection)count = int(result.getOutput(0))if count: print count arcpy.CopyFeatures.......
See: Get Count
You could use GetCount to count items in the layer before and after the selection and if selection is less than the original count and greater than zero then do the copy.
for map and pro
Layer—ArcPy | ArcGIS Desktop
Returns a layer's selection as a Python set of object IDs.
which will be > 0 if there is a selection.
If you don't have a layer, then use MakeFeatureLayer first then delete if needed
Retrieving data ...