I was provided an Excel Spreadsheet which had the definitions of fields for a feature class. There were several worksheets in the file, each containing field definitions for different feature classes. After a bit of cleanup, I converted each worksheet to a CSV with the following columns:
Field_Name
Field_Type
Field_Length
Field_Alias
Each of the CSV files had between 300 and 400 rows, which means there are that many fields (I know it's a lot of fields, but it's not my schema design).
I put together a bit of code to process the CSV files and create fields for the feature classes. Note, the feature classes already exist in a geodatabase and the CSV files have the same name as the feature classes.
The following code works, but it takes over 20 minutes to create 3 feature classes with 300-400 fields each.
count = 0
for csv_file in CSVList:
print csv_file
print count
with open(csv_file, 'rb') as csvfile:
reader = csv.reader(csvfile, delimiter = ',')
for line in reader:
field_name = line[0]
field_type = line[1]
field_length = line[2]
field_alias = line[3]
arcpy.AddField_management(FCList[count],field_name, field_type, "","",field_length,field_alias)
count+=1
Is there a more efficient way to create a feature class from a CSV file with field definitions? Or, is arcpy.AddField_management as good as it gets for this sort of thing?