<s> import arcpy <EOL> class FeatureIdGenerator ( object ) : <EOL> def __init__ ( self ) : <EOL> self . label = "<STR_LIT>" <EOL> self . description = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" <EOL> self . canRunInBackground = False <EOL> def getParameterInfo ( self ) : <EOL> in_gdb = arcpy . Parameter ( <EOL> displayName = "<STR_LIT>" , <EOL> name = "<STR_LIT>" , <EOL> datatype = "<STR_LIT>" , <EOL> parameterType = "<STR_LIT>" , <EOL> direction = "<STR_LIT>" ) <EOL> generation_field = arcpy . Parameter ( <EOL> displayName = "<STR_LIT>" , <EOL> name = "<STR_LIT>" , <EOL> datatype = "<STR_LIT>" , <EOL> parameterType = "<STR_LIT>" , <EOL> direction = "<STR_LIT>" ) <EOL> generation_field . filter . type = "<STR_LIT>" <EOL> generation_field . filter . list = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> generation_field . value = "<STR_LIT>" <EOL> hi_batchsize_field = arcpy . Parameter ( <EOL> displayName = "<STR_LIT>" , <EOL> name = "<STR_LIT>" , <EOL> datatype = "<STR_LIT>" , <EOL> parameterType = "<STR_LIT>" , <EOL> direction = "<STR_LIT>" ) <EOL> hi_batchsize_field . value = <NUM_LIT> <EOL> out_gdb = arcpy . Parameter ( <EOL> displayName = "<STR_LIT>" , <EOL> name = "<STR_LIT>" , <EOL> datatype = "<STR_LIT>" , <EOL> parameterType = "<STR_LIT>" , <EOL> direction = "<STR_LIT>" ) <EOL> out_gdb . parameterDependencies = [ in_gdb . name ] <EOL> parameters = [ in_gdb , generation_field , hi_batchsize_field , out_gdb ] <EOL> return parameters <EOL> def isLicensed ( self ) : <EOL> """<STR_LIT>""" <EOL> return True <EOL> def updateParameters ( self , parameters ) : <EOL> """<STR_LIT>""" <EOL> return <EOL> def updateMessages ( self , parameters ) : <EOL> """<STR_LIT>""" <EOL> return <EOL> def execute ( self , parameters , messages ) : <EOL> """<STR_LIT>""" <EOL> arcpy . env . workspace = parameters [ <NUM_LIT:0> ] . value <EOL> schema_version = parameters [ <NUM_LIT:1> ] . value <EOL> hi_batchsize = parameters [ <NUM_LIT:2> ] . value <EOL> generate_ID_table_name = "<STR_LIT>" <EOL> seqnameField = "<STR_LIT:name>" <EOL> seqcounterField = "<STR_LIT>" <EOL> seqintervalField = "<STR_LIT>" <EOL> if schema_version == "<STR_LIT>" or schema_version == "<STR_LIT>" : <EOL> generate_ID_table_name = "<STR_LIT>" <EOL> seqnameField = "<STR_LIT>" <EOL> seqcounterField = "<STR_LIT>" <EOL> seqintervalField = "<STR_LIT>" <EOL> new_table = None <EOL> counter_tbl_list = arcpy . ListTables ( generate_ID_table_name ) <EOL> if not counter_tbl_list : <EOL> arcpy . AddMessage ( "<STR_LIT>" + generate_ID_table_name + "<STR_LIT>" ) <EOL> new_table = True <EOL> generate_ID_table = arcpy . CreateTable_management ( arcpy . env . workspace , generate_ID_table_name ) <EOL> if schema_version == "<STR_LIT>" : <EOL> arcpy . AddField_management ( generate_ID_table , seqnameField , "<STR_LIT>" , None , None , <NUM_LIT:50> , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> arcpy . AddField_management ( generate_ID_table , seqcounterField , "<STR_LIT>" , None , None , None , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> arcpy . AddField_management ( generate_ID_table , seqintervalField , "<STR_LIT>" , None , None , None , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> if schema_version == "<STR_LIT>" or schema_version == "<STR_LIT>" : <EOL> arcpy . AddField_management ( generate_ID_table , seqnameField , "<STR_LIT>" , None , None , <NUM_LIT:50> , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> arcpy . AddField_management ( generate_ID_table , seqcounterField , "<STR_LIT>" , None , None , None , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> arcpy . AddField_management ( generate_ID_table , seqintervalField , "<STR_LIT>" , None , None , None , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> arcpy . AddField_management ( generate_ID_table , "<STR_LIT>" , "<STR_LIT>" , None , None , <NUM_LIT:255> , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> else : <EOL> new_table = False <EOL> generate_ID_table = counter_tbl_list [ <NUM_LIT:0> ] <EOL> fc_list = arcpy . ListFeatureClasses ( ) <EOL> for fc in fc_list : <EOL> arcpy . AddMessage ( "<STR_LIT>" + fc ) <EOL> counter = <NUM_LIT:0> <EOL> baseCount = <NUM_LIT:0> <EOL> interval = hi_batchsize <EOL> if new_table : <EOL> insert_new_counter_cursor = arcpy . da . InsertCursor ( generate_ID_table_name , [ seqnameField , seqcounterField , seqintervalField ] ) <EOL> insert_new_counter_cursor . insertRow ( ( fc , <NUM_LIT:0> , hi_batchsize ) ) <EOL> del insert_new_counter_cursor <EOL> counterParams = None <EOL> escaped_name = arcpy . AddFieldDelimiters ( generate_ID_table_name , seqnameField ) <EOL> where_clause = escaped_name + "<STR_LIT>" + "<STR_LIT:'>" + fc + "<STR_LIT:'>" <EOL> with arcpy . da . SearchCursor ( generate_ID_table_name , [ seqnameField , seqcounterField , seqintervalField ] , where_clause ) as rows : <EOL> for counterRow in rows : <EOL> counterParams = counterRow <EOL> break <EOL> if counterParams != None : <EOL> baseCount = counterParams [ <NUM_LIT:1> ] <EOL> interval = counterParams [ <NUM_LIT:2> ] <EOL> else : <EOL> insert_new_counter_cursor = arcpy . da . InsertCursor ( generate_ID_table_name , [ seqnameField , seqcounterField , seqintervalField ] ) <EOL> insert_new_counter_cursor . insertRow ( ( fc , <NUM_LIT:0> , hi_batchsize ) ) <EOL> del insert_new_counter_cursor <EOL> with arcpy . da . SearchCursor ( generate_ID_table_name , [ seqnameField , seqcounterField , seqintervalField ] ) as rows : <EOL> for row in rows : <EOL> if row [ <NUM_LIT:0> ] == fc : <EOL> baseCount = row [ <NUM_LIT:1> ] <EOL> interval = row [ <NUM_LIT:2> ] <EOL> break <EOL> self . incrementCounter ( generate_ID_table_name , seqnameField , seqcounterField , fc , baseCount + interval ) <EOL> fid_name = fc + "<STR_LIT>" <EOL> fields_list = arcpy . ListFields ( fc , fid_name ) <EOL> if not fields_list : <EOL> arcpy . AddField_management ( fc , fid_name , "<STR_LIT>" , None , None , <NUM_LIT:50> , "<STR_LIT>" , None , None ) <EOL> with arcpy . da . UpdateCursor ( fc , [ fid_name ] ) as rows : <EOL> for row in rows : <EOL> if row [ <NUM_LIT:0> ] == None : <EOL> if counter >= interval : <EOL> arcpy . AddMessage ( "<STR_LIT>" ) <EOL> with arcpy . da . SearchCursor ( generate_ID_table_name , [ seqcounterField ] , where_clause ) as rows : <EOL> for counterRow in rows : <EOL> baseCount = counterRow [ <NUM_LIT:0> ] <EOL> break <EOL> counter = <NUM_LIT:0> <EOL> row [ <NUM_LIT:0> ] = fc + "<STR_LIT:/>" + str ( baseCount + counter ) <EOL> counter += <NUM_LIT:1> <EOL> rows . updateRow ( row ) <EOL> with arcpy . da . UpdateCursor ( generate_ID_table_name , [ seqnameField , seqcounterField ] ) as rows : <EOL> for newRow in rows : <EOL> if newRow [ <NUM_LIT:0> ] == fc : <EOL> newRow [ <NUM_LIT:1> ] = baseCount + counter <EOL> rows . updateRow ( newRow ) <EOL> break <EOL> arcpy . AddMessage ( "<STR_LIT>" ) <EOL> return <EOL> def incrementCounter ( self , generate_ID_table_name , seqnameField , seqcounterField , fcName , newCount ) : <EOL> with arcpy . da . UpdateCursor ( generate_ID_table_name , [ seqnameField , seqcounterField ] ) as rows : <EOL> for row in rows : <EOL> if row [ <NUM_LIT:0> ] == fcName : <EOL> row [ <NUM_LIT:1> ] = newCount <EOL> rows . updateRow ( row ) <EOL> break </s>
