AnsweredAssumed Answered

Python and Relates

Question asked by cynthiak on Oct 30, 2014
Latest reply on Nov 1, 2014 by bixb0012

I am new to Python, so this may have a simple answer.  This is something that I used to write in AML in 10 minutes.  I want to relate a feature class to a table, select all records in the feature class - which would select related records in the table, do a switch selection on the table and create a new feature from the table.  My script does what it is supposed to when I use a small sample set, but totally crashes ArcMap so that it closes completely about 1/4 of the way through the full (13,000) records.  I believe it has something to do with the nested cursors that I have going.  How can I keep it from crashing and closing and finish the script?  Any help would be great!  Or if there is an easier way to do a relate in python??

 

This is the piece where is does a "relate" and ArcMap closes..........

 

# Create a search cursor to loop through the building_pt_sewer table
arcpy.SelectLayerByAttribute_management("building_clip", "NEW_SELECTION", "OBJECTID > 0")
buildings = arcpy.SearchCursor("building_clip")
parc_field = "parcels_ASSESSOR_N_1"


for building in buildings:
    #Get Parcel Number of building
    building_ID = building.getValue(parc_field)


    # Create search cursor for looping through the buildings
    sewers = arcpy.SearchCursor(DestinationTable)
    sewer_field = "parcel_id"


    for sewer in sewers:
        #Get parc of sewer
        sewer_parc = sewer.getValue(sewer_field)


        query = "parcel_id = " + "'%s'" %building_ID
        print query
        arcpy.SelectLayerByAttribute_management(DestinationTable, "ADD_TO_SELECTION", query)
  #     break
del buildings, sewers

Outcomes