I am working on a Python script that will count how many selected features there are and if there are it will make a feature layer from them. If the script runs and finds there are 0 selected records it should print 'NO SELECTED RECORDS'. However when I run my script it is ignoring my If Then statement and creating a duplicate layer of "Locates", but still telling me I have no records selected.
Here is my code:
import arcpy totalCount = arcpy.GetCount_management("Locates") print 'Total Record Count = ' + `totalCount` try: arcpy.SelectLayerByLocation_management("Locates","INTERSECT","Boxes",0,"NEW_SELECTION","INVERT") arcpy.SelectLayerByLocation_management("Locates","INTERSECT","Lines",0,"REMOVE_FROM_SELECTION") ##GET COUNT OF SELECTED RECORDS selectedCount = len(arcpy.Describe("Locates").FIDSet.split('; '))-1 print 'Selected Records Count' + `selectedCount` if selectedCount != totalCount: ##IF SELECTED ROWS NOT EQUAL TO 0 THEN MAKE FEATURE LAYER ELSE PRINT 'NO LOCATES TO CLOSE' arcpy.MakeFeatureLayer_management("Locates","NeedToCLOSE") for row in arcpy.SearchCursor("NeedToCLOSE"): print 'Close Work Order #' + `row.WorkOrderID` else: print 'No Locates to close' except: print(arcpy.GetMessages())
What do I need to change in my code for this to work?