This script should make a field for all the feature classes in a geodatabase, populate the new field with the name of the feature class it's being created in, and then merge all the feature classes together. However, when I run the code I get the success message but only the first feature class features are in the output of the merged feature class.

import arcpy, os

arcpy.env.workspace = r"J:\Non_RS_MXDs\Crown_Scrap.gdb"

for fc in arcpy.ListFeatureClasses():
    arcpy.AddField_management(fc, "DyRt", "TEXT", field_length = 30)
    with arcpy.da.UpdateCursor(fc, "DyRt") as cursor:
        for row in cursor:
            row[0] = fc

fClasses = []
i = 0

    fcs = arcpy.ListFeatureClasses()
    for fc in fcs:
        print fc
        i = i+1

except Exception as err:
    print err

    arcpy.Merge_management([fClasses], "Rts_8_15")
    print "merge: SUCCESS!"

    #count number of new features
    result1 = int(arcpy.GetCount_management("Rts_8_15").getOutput(0))
    print result1

except Exception as err:
    print "merge: FAIL :("
    print err

You are creating a nested list which is probably throwing off the tool. Try changing the line where you are calling the merge to:

arcpy.Merge_management(fClasses, "Rts_8_15")

You may also want to add a print statement to show how many feature classes you are merging.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.