1

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
 cursor.updateRow(row)
fClasses = []
i = 0
try:
 fcs = arcpy.ListFeatureClasses()
 for fc in fcs:
 print fc
 fClasses.append(fc)
 i = i+1
except Exception as err:
 arcpy.AddError(err)
 print err
try:
 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:
 arcpy.AddError(err)
 print "merge: FAIL :("
 print err
asked Oct 15, 2015 at 1:27
0

1 Answer 1

2

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.

answered Oct 15, 2015 at 2:24

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.