I'm doing a script in ArcMap and I'm new to this. I have to append some field from a table to another, I did this script in Python but I have a problem when it want make the Mapping field with a field of type shape shape I mean = point, line, polygon ..
The error that I get is this one:
FieldMap: Error in adding input field to field map
Failed to execute (script).
My code is:
# import system modules
import arcpy, os
from arcpy import env
# get parameters
tabellaInput = arcpy.GetParameterAsText(0)
tabellaOutput = arcpy.GetParameterAsText(1)
# Set local variables
fieldMappings = arcpy.FieldMappings()
# add the table to field mapping
fieldMappings.addTable(tabellaOutput)
fieldnames = [f.name for f in arcpy.ListFields(tabellaInput)]
fieldnamesOut = [f.name for f in arcpy.ListFields(tabellaOutput)]
for elem in fieldnames:
arcpy.AddMessage(str(elem));
if str(elem) not in fieldnamesOut:
continue
#creat a field map for each field.
fldMap = arcpy.FieldMap()
fldMap.addInputField(tabellaInput,elem) # deve aggiugere questo field
# Set name of new output field
namefield = fldMap.outputField
namefield.name = elem
fldMap.outputField = namefield
# Add output field to field mappings object
fieldMappings.addFieldMap(fldMap)
schemaType = "NO_TEST"
subtype = ""
try:
# Process: Append the feature classes into feature class
arcpy.Append_management(tabellaInput, tabellaOutput, schemaType, fieldMappings, subtype)
except:
# If an error occurred while running a tool print the messages
print arcpy.GetMessages()
it does stop inside the
for....
when come a field of type shape
in fact, if I add inside the
for
the following line of code:
if elem == 'Shape':
continue
it works fine.
Another thing is that I have more fields in the input table than the target table.
Why don't I see all the fields of the input table in the target?
2 Answers 2
You do not need to add the SHAPE field to mapping. It will always be included and remain in the feature class.
You cannot seem to rename it either.
There was a very similar problem described and resolved in the old ArcGIS Discussion Forums.
The solution seems to have been to use Add and Calculate Field to make sure that the input fields on all input tables are absolutely identical.