cgnadinger

Please Help: Python Script to Automatically add Unique IDs to new features

Discussion created by cgnadinger on Oct 12, 2011
Latest reply on Oct 26, 2011 by rfairhur24
I found a script on here, somewhere, and have been trying to edit it for my purposes. Right now I'm trying to test it out on a sample on my local computer to make sure it will work before attempting anything more.

Ultimately, I am trying to set up a script to run through the Scheduled Tasks that will go through a series of SDE datasets and assign unique IDs to the newly added features. I actually want it to assign the unique ID as a letter/number combination (i.e. FH0003001) but at the moment I can't get the simple number part to work in my favor.

(I'm coming from the VB side and still very green with Python.)


This is what I've been trying to use so far, however I am getting the error that says "return convertArcObjectToPythonObject(self._arc_object.UpdateRow(*gp_fixargs(args)))" RuntimeError: ERROR 999999: Error executing function

Anyway, any guidance you can offer both with this sample set and in moving forward to my ultimate goal would be greatly appreciated!


import arcpy
from arcpy import env
import string

env.workspace = "C:\\Users\\gisadmin\\Desktop\\TEST"

filter = '' 

cur = arcpy.UpdateCursor("C:\\Users\\gisadmin\\Desktop\\TEST\\FH_Test.shp", filter)

i = 0
for row in cur:
    i += 1
    row.FACILITY_I = str(i) #This is the label for the column you want to update, eg. OID

cur.updateRow(row)



As far as this: C:\\Users\\gisadmin\\Desktop\\TEST\\FH_Test.shp I've done it with \\ and with \ .. I read somewhere about the \t causing an issue but regardless it hasn't worked either way.

Outcomes