arcpy.Append_management how to match from/to fields with different names

323
6
06-25-2019 10:51 AM
JoseSanchez
Occasional Contributor III

Hello

How do I match FCFrom field "Point_X"  with  FCTo field "PointX"    before doing an arcpy.Append_management  

# Create a new fieldmappings and add the two feature classes.
    fieldmappings = arcpy.FieldMappings()
    fieldmappings.addTable(FCFrom)
    fieldmappings.addTable(FCTo)
    schemaType = "NO_TEST "

   ????  how do I match FCFrom field "Point_X"  with  FCTo field "PointX" 

    arcpy.Append_management(FCFrom, FCTo, schemaType, fieldMappings, subtype)

Tags (1)
0 Kudos
6 Replies
DanPatterson_Retired
MVP Esteemed Contributor
0 Kudos
JoseSanchez
Occasional Contributor III

I want to populate the field CAPDESC  with  the field "CAP_DESC" .

What am I missing?

I am getting this error message :

ERROR 000800: The value is not a member of TEST | NO_TEST.

 

 Create a new fieldmappings and add the two feature classes.
    fieldmappings = arcpy.FieldMappings()
    fieldmappings.addTable(FCFrom)
    fieldmappings.addTable(FCTo)
    schemaType = "NO_TEST "

   fieldmappings.replaceFieldMap(fieldmappings.findFieldMapIndex("CAPDESC"), fieldmap)
    fieldmap.addInputField(FCFrom, "CAP_DESC")
    fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("CAP_DESC"))

 arcpy.Append_management(FCFrom, FCTo, schemaType, fieldmappings)

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

Jose, you have use "CAPDESC" 3 times, in the code example they used the sequence "TRACT2000""TRACTCODE", "TRACT2000"

Code with line numbers would help

/blogs/dan_patterson/2016/08/14/script-formatting  

0 Kudos
JoseSanchez
Occasional Contributor III

Changed the code:

   fieldmap = fieldmappings.getFieldMap(fieldmappings.findFieldMapIndex("CAPDESC"))
    fieldmap.addInputField(FCFrom, "CAP_DESC")
    fieldmappings.replaceFieldMap(fieldmappings.findFieldMapIndex("CAPDESC"), fieldmap)
    fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("CAP_DESC"))

Same error:

Failed to execute. Parameters are not valid.

ERROR 000800: The value is not a member of TEST | NO_TEST.

Failed to execute (Append).

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor
0 Kudos
JoseSanchez
Occasional Contributor III

Finally I found the error: in the variable   schemaType = "NO_TEST "      the string  "NO_TEST  "  had a space at the end. I removed the space  schemaType = "NO_TEST", and now it works.

 #Target Layer
    fieldmappings.addTable(FCto)
    #Append Layer
    fieldmappings.addTable(FCFrom)

    schemaType = "NO_TEST"


    fieldmap = fieldmappings.getFieldMap(fieldmappings.findFieldMapIndex("CAPDESC"))

    fieldmap.addInputField(FCFrom, "CAP_DESC")
    fieldmappings.replaceFieldMap(fieldmappings.findFieldMapIndex("CAPDESC"), fieldmap)
   

    arcpy.Append_management(FCFrom, FCto, schemaType, fieldmappings)

0 Kudos