

Print 'Total time: ' + str(endtime1) +'s' # about 3.5 seconds NewCopy = "output_" + str(outCounter) + '.shp'Īrcpy.Append_management(fc, newCopy, 'NO_TEST') Template = 'template.shp' # the template FCįcs = arcpy.ListFeatureClasses('*Copy*') # the "other" FCs I'd say the code is somewhat simpler, as well.Ī = r'C:\junk\new_fields'

For small feature classes, the differences are pretty small, but for large datasets, the time difference could be considerable. See below where Test A uses feature class level tools and Test B uses field level tools (I believe these are comparing apples to apples, but I could be wrong).

I'm sure someone more proficient with python could show a better way.įor what it's worth, running the built-in feature class level tools (Copy, then Append) seems to work about twice as fast as adding fields individually. #Adding field based on field attributes of original fieldĪrcpy.AddField_management(shape, field, field, field, field, field, field, field, field) #Creating List of FeatureClasses in workspace #Appending list of field elements to new field listĪ = "directoryofshapefiles" #Appending all relevant field object elements as strings to listįield_attributes.append(field.name, field.type, field.precision, field.scale, field.length, field.aliasName, field.isNullable, field.required) #Creating empty list to append field attributes to #Creating empty list to append field attribute list to #Creating variable for template file path

I do not have data to test on at the moment, so this is untested and I can't show the output. If your other shapefiles were in multiple directories or subdirectories, we would need to use the os module walk function, or arcpy.da.Walk to create the list of shapes. In the below example, your "template" shapefile needs to be in a seperate directory from the rest, since this script does not check to see if a field already exists. This is far from an ideal solution, since I am uncomfortable with dictionaries, I make a list of lists that contain the attributes for existings fields using the arcpy module.
