1

I need to append two shapefiles together. The append tool works within the ArcMap toolboxes AND Python window, but it does not work when copying over the python snippet to PyScripter. It'll completely run through but won't produce values within the fields (all values will be empty or null).

I'm assuming it has something to do with the FieldMapping() objects?

import arcpy

arcpy.env.overwriteOutput = True
arcpy.env.workspace = r"C:\Users\Documents\ArcGIS\Default.gdb"

tc = r"testing_append"
changesshp = r"C:\Users\gfrederick\Documents\Scripts\changes.shp"

lyr1 = arcpy.MakeFeatureLayer_management(tc, "tc_lyr")
lyr2 = arcpy.MakeFeatureLayer_management(changesshp, "change.lyr")


arcpy.Append_management(lyr2, lyr1, schema_type="NO_TEST", field_mapping="""RECORDNUM "RECORDNUM" true false false 19 Double 10 18 ,First,#,changes_new,RECORDNUM,-1,-1;TAKENBY "TAKENBY" true false false 50 Text 0 0 ,First,#,changes_new,TAKENBY,-1,-1;SETDATE "SETDATE" true true false 8 Date 0 0 ,First,#,changes_new,SETDATE,-1,-1;SETYEAR "SETYEAR" true false false 4 Text 0 0 ,First,#;MCD "MCD" true false false 50 Text 0 0 ,First,#,changes_new,MCD,-1,-1;RDPREFIX "RDPREFIX" true false false 50 Text 0 0 ,First,#,changes_new,RDPREFIX,-1,-1;ROUTE "ROUTE" true false false 19 Double 10 18 ,First,#,changes_new,ROUTE,-1,-1;ROAD "ROAD" true false false 50 Text 0 0 ,First,#,changes_new,ROAD,-1,-1;CNTDIR "CNTDIR" true false false 50 Text 0 0 ,First,#,changes_new,CNTDIR,-1,-1;FROMLMT "FROMLMT" true false false 50 Text 0 0 ,First,#,changes_new,FROMLMT,-1,-1;TOLMT "TOLMT" true false false 50 Text 0 0 ,First,#,changes_new,TOLMT,-1,-1;TYPE "TYPE" true false false 20 Text 0 0 ,First,#,changes_new,TYPE,-1,-1;RDSUFFIX "RDSUFFIX" true false false 15 Text 0 0 ,First,#,changes_new,RDSUFFIX,-1,-1;LATITUDE "LATITUDE" true false false 19 Double 8 18 ,First,#,changes_new,LATITUDE,-1,-1;LONGITUDE "LONGITUDE" true false false 19 Double 8 18 ,First,#,changes_new,LONGITUDE,-1,-1;FACTOR "FACTOR" true false false 19 Double 8 18 ,First,#,changes_new,FACTOR,-1,-1;AXLE "AXLE" true false false 19 Double 8 18 ,First,#,changes_new,AXLE,-1,-1;AADT "AADT" true false false 9 Long 0 9 ,First,#,changes_new,AADT,-1,-1;UPDATED "UPDATED" true true false 8 Date 0 0 ,First,#;CO_NAME "CO_NAME" true false false 35 Text 0 0 ,First,#;MUN_NAME "MUN_NAME" true false false 40 Text 0 0 ,First,#""", subtype="")
  • 1
    It is too hard to tell from the massive field mapping string. It would probably be easier to set up the field mapping using the FieldMap class. Also, I'm not sure, but it looks like it is looking for a table called "change_new" for the target layer. It appears that the sample you're trying is using a layer called "change". – crmackey Dec 21 '15 at 20:02
  • Rather than providing an answer within your question, it is better to do that as an answer. Self-answering is fine to do here, and encouraged. – PolyGeo Dec 22 '15 at 20:49
1

There a code example:

import arcpy

tc = r"tc.shp"
changesshp = r"_changes.shp"

fieldmapping = arcpy.FieldMap()
fieldmapping.addTable(changesshp)

arcpy.Append_management(changesshp, tc, "NO_TEST", fieldmapping)

print('YAAASSSSS')

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.