Select to view content in your preferred language

field mapping - 2x vs 3x different results

541
2
Jump to solution
10-13-2023 02:14 PM
RDCOGIS
Occasional Contributor

Hi,

I'm finally converting 2x scripts to 3x and I'm getting poor results from the same code.  Exact same code running under the two different environments, different results.

Here is the code. Simple merge of three layers into one, mapping only one field. In 3x it will not populate the field from one of the layers. Works fine in 2x. What changed or what do I need to change in the new API.

I should mention that for testing purposes, all FCs are in the same, new file geodatabase.

 

    fldFolio = arcpy.Field()
    fldFolio.name = 'Folio'
    fldFolio.aliasName = 'Folio'
    fldFolio.type = 'Text'
    fldFolio.length = 12
    fldFolio.isNullable = True

    fm = arcpy.FieldMap()
    fm.outputField = fldFolio
    fm.addInputField(PIDless_lyr, 'Folio', 0, 12)
    fm.addInputField(target_ParcelsSingle, 'BCA_Legal_Folio', 0, 12)
    fm.addInputField(target_ParcelsStrata, 'BCA_Legal_Folio', 0, 12)

    fms = arcpy.FieldMappings()
    fms.addFieldMap(fm)

    # merge everything
    print('Merge all Except MHs')
    arcpy.Merge_management([PIDless_lyr, target_ParcelsSingle, target_ParcelsStrata], target_ParcelsTmp1, fms)

 

1 Solution

Accepted Solutions
RDCOGIS
Occasional Contributor

one of the layers I'm Merging is an in-memory Feature Layer. Field Mapping did not like this. I copied the data to a physical Feature Class and all is well.

bug?....

View solution in original post

0 Kudos
2 Replies
RDCOGIS
Occasional Contributor

one of the layers I'm Merging is an in-memory Feature Layer. Field Mapping did not like this. I copied the data to a physical Feature Class and all is well.

bug?....

0 Kudos
ChelseaRozek
MVP Regular Contributor

Not sure if this is your issue, but I was also having trouble with upgrading some field mapping scripts to Python 3.x. I noticed that attributes were blank in the output even though they were properly mapped. When I printed the field mapping result, I noticed the slashes were opposite the ones in the Python code that is created from Pro's append gp tool. So when I added .exportToString().replace("/","\\"), on to the end of the field mapping result, the rest of my code worked and all my values populate now. 

0 Kudos