desc = arcpy.Describe(lyr) if not desc.FIDSet == '': print 'Layer has a selection'
Layer Describe properties has an FIDSet property which returns a semicolon-delimited string of selected feature IDs. If the string is empty no features are selected: desc = arcpy.Describe(lyr) if not desc.FIDSet == '': print 'Layer has a selection'
I would think that you could get an initial count and assign as say numRecords then run a selection and set another get count as selRecords. then check if the selected count is null
arcpy.SelectLayerByAttribute_management(layer.name,"ADD_TO_SELECTION",'"OBJECTID" = 1000000000000') featurecount = int(arcpy.GetCount_management(layer.name).getOutput(0)) if featurecount > 0: #Do Something else: arcpy.SelectLayerByAttribute_management(layer.name, "CLEAR_SELECTION")
Yes, there are many ways to do this, here is one: result = int(arcpy.GetCount_management(Parcels).getOutput(0)) if result: # do something else: print 'No selected features'
result = int(arcpy.GetCount_management(Parcels).getOutput(0)) if result: # do something else: print 'No selected features'
Hi,I trying to create an arcpy script that will run only if there are selected features in a layer, however I can't figure out how to get arcpy to test for selected features.I've read posts about using GetCount, however this seems to only work if there is a difference in the number of selected features to the full feature count of the layer. I want my script to run even if EVERY feature in the layer is selected (but ONLY if features are selected).Is there a way I can do this?Cheers,Mike.
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.