Skip to main content
Expanded on reasoning and provided link to arcpy documentation.
Source Link
Luke T
  • 103
  • 7

In your second loop where you

print fm.outputfield.name

add another line to

print fm.inputfield.name

to check if your fieldmap object has input fields. You want every FieldMap object to have both an input and output field name, otherwise the fieldmappings object is not used by the tool.

The documentation has some good examples on this idea, fieldmapping docs.

Below is an example of how I use fieldmappings to append from a shapefile to a featureclass.

address_fms = arcpy.FieldMappings()
try:
    # Start loop to make and add fieldmaps to fieldmappings object
    for i in range(61):
        str_i = str(i)
        ## Assign a fieldmap object to a variable
        str_i = arcpy.FieldMap()
        ## Attribute the object's InputField
        str_i.addInputField(intable, inflds[i])
        ## Assign the outputField object to a variable
        fm_name = str_i.outputField
        ## Attribute the outputField object's name attribute
        fm_name.name = outflds[i]
        ## Assign the field object with a populated name value
        ## to the fieldmap object
        str_i.outputField = fm_name
        # Add them to fieldmappings object so it works
        address_fms.addFieldMap(str_i)

In your second loop where you

print fm.outputfield.name

add another line to

print fm.inputfield.name

to check if your fieldmap object has input fields.

Below is an example of how I use fieldmappings to append from a shapefile to a featureclass.

address_fms = arcpy.FieldMappings()
try:
    # Start loop to make and add fieldmaps to fieldmappings object
    for i in range(61):
        str_i = str(i)
        ## Assign a fieldmap object to a variable
        str_i = arcpy.FieldMap()
        ## Attribute the object's InputField
        str_i.addInputField(intable, inflds[i])
        ## Assign the outputField object to a variable
        fm_name = str_i.outputField
        ## Attribute the outputField object's name attribute
        fm_name.name = outflds[i]
        ## Assign the field object with a populated name value
        ## to the fieldmap object
        str_i.outputField = fm_name
        # Add them to fieldmappings object so it works
        address_fms.addFieldMap(str_i)

In your second loop where you

print fm.outputfield.name

add another line to

print fm.inputfield.name

to check if your fieldmap object has input fields. You want every FieldMap object to have both an input and output field name, otherwise the fieldmappings object is not used by the tool.

The documentation has some good examples on this idea, fieldmapping docs.

Below is an example of how I use fieldmappings to append from a shapefile to a featureclass.

address_fms = arcpy.FieldMappings()
try:
    # Start loop to make and add fieldmaps to fieldmappings object
    for i in range(61):
        str_i = str(i)
        ## Assign a fieldmap object to a variable
        str_i = arcpy.FieldMap()
        ## Attribute the object's InputField
        str_i.addInputField(intable, inflds[i])
        ## Assign the outputField object to a variable
        fm_name = str_i.outputField
        ## Attribute the outputField object's name attribute
        fm_name.name = outflds[i]
        ## Assign the field object with a populated name value
        ## to the fieldmap object
        str_i.outputField = fm_name
        # Add them to fieldmappings object so it works
        address_fms.addFieldMap(str_i)
added 24 characters in body
Source Link
Luke T
  • 103
  • 7

In your second loop where you print fm.outputfield.name

print fm.outputfield.name

add another line to print fm.inputfield.name

print fm.inputfield.name

to check if your fieldmap object has input fields.

Below is an example of how I use fieldmappings to append from a shapefile to a featureclass.

address_fms = arcpy.FieldMappings()
try:
    # Start loop to make and add fieldmaps to fieldmappings object
    for i in range(61):
        str_i = str(i)
        ## Assign a fieldmap object to a variable
        str_i = arcpy.FieldMap()
        ## Attribute the object's InputField
        str_i.addInputField(intable, inflds[i])
        ## Assign the outputField object to a variable
        fm_name = str_i.outputField
        ## Attribute the outputField object's name attribute
        fm_name.name = outflds[i]
        ## Assign the field object with a populated name value
        ## to the fieldmap object
        str_i.outputField = fm_name
        # Add them to fieldmappings object so it works
        address_fms.addFieldMap(str_i)

In your second loop where you print fm.outputfield.name add another line to print fm.inputfield.name to check if your fieldmap object has input fields.

Below is an example of how I use fieldmappings to append from a shapefile to a featureclass.

address_fms = arcpy.FieldMappings()
try:
    # Start loop to make and add fieldmaps to fieldmappings object
    for i in range(61):
        str_i = str(i)
        ## Assign a fieldmap object to a variable
        str_i = arcpy.FieldMap()
        ## Attribute the object's InputField
        str_i.addInputField(intable, inflds[i])
        ## Assign the outputField object to a variable
        fm_name = str_i.outputField
        ## Attribute the outputField object's name attribute
        fm_name.name = outflds[i]
        ## Assign the field object with a populated name value
        ## to the fieldmap object
        str_i.outputField = fm_name
        # Add them to fieldmappings object so it works
        address_fms.addFieldMap(str_i)

In your second loop where you

print fm.outputfield.name

add another line to

print fm.inputfield.name

to check if your fieldmap object has input fields.

Below is an example of how I use fieldmappings to append from a shapefile to a featureclass.

address_fms = arcpy.FieldMappings()
try:
    # Start loop to make and add fieldmaps to fieldmappings object
    for i in range(61):
        str_i = str(i)
        ## Assign a fieldmap object to a variable
        str_i = arcpy.FieldMap()
        ## Attribute the object's InputField
        str_i.addInputField(intable, inflds[i])
        ## Assign the outputField object to a variable
        fm_name = str_i.outputField
        ## Attribute the outputField object's name attribute
        fm_name.name = outflds[i]
        ## Assign the field object with a populated name value
        ## to the fieldmap object
        str_i.outputField = fm_name
        # Add them to fieldmappings object so it works
        address_fms.addFieldMap(str_i)
Source Link
Luke T
  • 103
  • 7

In your second loop where you print fm.outputfield.name add another line to print fm.inputfield.name to check if your fieldmap object has input fields.

Below is an example of how I use fieldmappings to append from a shapefile to a featureclass.

address_fms = arcpy.FieldMappings()
try:
    # Start loop to make and add fieldmaps to fieldmappings object
    for i in range(61):
        str_i = str(i)
        ## Assign a fieldmap object to a variable
        str_i = arcpy.FieldMap()
        ## Attribute the object's InputField
        str_i.addInputField(intable, inflds[i])
        ## Assign the outputField object to a variable
        fm_name = str_i.outputField
        ## Attribute the outputField object's name attribute
        fm_name.name = outflds[i]
        ## Assign the field object with a populated name value
        ## to the fieldmap object
        str_i.outputField = fm_name
        # Add them to fieldmappings object so it works
        address_fms.addFieldMap(str_i)