I have been having a heck of a time trying to get this script to run. The best I get is it will run once, and crash the app the second time. This makes me think it is a locking issue. I haven't been able to get a clear reference on how this is handled in python / arcpy. I am running 10.0 sp3, the referenced layers are in a file geodatabase for now. I eventually wish to modify a SDE feature class, but I want to work out the bugs before I point this at my database. The commented out lines are my attempts to isolate problematic portions of script. The long term goal of this script will be to copy the geometry from one feature class to another with a matching "MC911_ID" field, but I am stuck here thus far. Any assistance is greatly appreciated. import arcpy
try:
drow, drows = None, None
deltas = arcpy.mapping.Layer("Deltas")
base = arcpy.mapping.Layer("Baseline")
dShape = arcpy.Describe(deltas).shapeFieldName
bShape = arcpy.Describe(base).shapeFieldName
drows = arcpy.SearchCursor("Deltas")
dcount = 0
bcount = 0
arcpy.SelectLayerByAttribute_management("Baseline","CLEAR_SELECTION")
arcpy.SelectLayerByAttribute_management("Deltas","CLEAR_SELECTION")
for drow in drows:
dID = drow.MC911_ID
print("drow-" + str(dID))
brow, brows = None, None
brows = arcpy.UpdateCursor("Baseline",'"MC911_ID" = ' + str(dID))
for brow in brows:
bID = brow.MC911_ID
## brow.MC911ID = 'Row Checked: ' + str(datetime.datetime.now())
brows.updateRow(brow)
bcount = bcount +1
if bID == dID:
## brow.setValue("MC911ID", 'Matched')
## brows.updateRow(brow)
print("Match-" + str(bID))
## brows.close()
break
del brow
del brows
dcount = dcount +1
## drows.close()
print dcount
print bcount
print('Script Complete')
except Exception as e:
if not arcpy.GetMessages() == "":
arcpy.AddMessage(arcpy.GetMessages(2))
print("I am so sorry, there is a problem...")
print e.message
print dcount
print bcount
finally:
# Regardless of whether the script succeeds or not, delete
# the row and cursor
#
if drow:
del drow
if drows:
del drows
if deltas:
del deltas
if base:
del base