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)
-
1What version of ArcGIS do you work with?Alex Tereshenkov– Alex Tereshenkov2015年04月17日 06:38:48 +00:00Commented Apr 17, 2015 at 6:38
1 Answer 1
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.
-
1To 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– Hornbydd2015年04月17日 10:20:48 +00:00Commented Apr 17, 2015 at 10:20
-
superrache, do you have an example of this?Geoffrey West– Geoffrey West2015年04月17日 18:08:22 +00:00Commented Apr 17, 2015 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– superrache2015年04月20日 07:23:18 +00:00Commented Apr 20, 2015 at 7:23