0

I am using an update cursor to add values in a try:except block of code using ArcPy. If the code is successful I log yes in the success field, if it reaches the except block I log yes in the fail field. I also log the time of the succeeds or fail. However, my Object ID is doing very strange things.

The first two object IDs populated this table on one execution of the script, the others came at 2 other times. I would ideally like to see 1-6, not 1,2,401,402,801,802 as noted in the screenshot.

enter image description here

code snippet which reflects table

except:
rows = arcpy.InsertCursor(aTable)
for x in xrange(0, outputobjects):
    row = rows.newRow()
row.setValue("Success", 'NO')
row.setValue("Fail", 'YES')
row.setValue("Time", Start)
rows.insertRow(row)
logger.exception("Something has gone wrong!")
print "the try has failed!"

try:
    arcpy.FeatureClassToFeatureClass_conversion(failhandletest)
except:
    logger.exception("This works for the nested exception and fail has been logged in History_Table")
    rows = arcpy.InsertCursor(aTable)

for x in xrange(0, outputobjects):
    row = rows.newRow()
row.setValue("Success", 'NO')
row.setValue("Fail", 'YES')
row.setValue("Time", Start)
rows.insertRow(row)
  • 1
    What version of ArcGIS do you work with? – Alex Tereshenkov Apr 17 '15 at 6:38
4

Yes this behaviour could seem strange but it's perfectly normal.

Object Ids are managed by the geodatabase system, which maybe jump from 2 to 400 in case of the first process is still running.

If you want ids from 1 to 6 for your features, you have to populate your own field ID than the system field OBJECTID. At the start of your script, get the max value of ID, then increase it each time your insert a new row.

  • 1
    To add to this answer, I'm not at my pc to test this but I think you can compact a database to reset the sequence or is export? Never can remember! – Hornbydd Apr 17 '15 at 10:20
  • superrache, do you have an example of this? – Geoffrey West Apr 17 '15 at 18:08
  • nop, and I am not very python friendly (more Java). At the start of the script, check the existence of the field ID, create it if it doesnt exist. Then, with a search cursor, iterate each feature of your table to get the max of row.getValue("ID"). – superrache Apr 20 '15 at 7:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.