Select to view content in your preferred language

Merge_management with field mapping strange output

719
5
01-03-2024 01:07 AM
StuartMoore
Frequent Contributor

i'm trying to use the suggestion in this post from @RandyBurton

https://community.esri.com/t5/python-questions/merge-with-field-mapping/m-p/560853/highlight/true#M4... 

to merge 25 or so shp files and map the fields but using the code i get a strange output

StuartMoore_0-1704212040714.png

any suggestions?

 

Stu

Tags (2)
0 Kudos
5 Replies
BlakeTerhune
MVP Regular Contributor

Hi @StuartMoore. Could you please include the code snippet you're running? Are you working in ArcMap or ArcGIS Pro?

0 Kudos
StuartMoore
Frequent Contributor

 

 

        fields = [
        ['LINENAME "LINENAME" true true false 100 Text 0 0,First,#,{0};', '{0},LINENAME,0,50'],
        ['LAUNCH "LAUNCH" true true false 100 Text 0 0,First,#,{0};', '{0},LAUNCH,0,50'],
        ['RECEIVER "RECEIVER" true true false 100 Text 0 0,First,#,{0};', '{0},RECEIVER,0,50'],
        ['PROJNO "PROJNO" true true false 100 Text 0 0,First,#,{0};', '{0},PROJNO,0,50'],
        ['INSPTYPE "INSPTYPE" true true false 100 Text 0 0,First,#,{0};', '{0},INSPTYPE,0,50'],
        ['INSPDATE "INSPDATE" true true false 100 Text 0 0,First,#,{0};', '{0},INSPDATE,0,50'],
        ]

        fmap = ''

        for fld in fields:
            fm = []
            for fc in r_plin:
                fm.append(fld[1].format(fc))
                fmap = fmap + fld[0].format(','.join(fm))
                            
        messages.addMessage(fmap)

        #messages.addMessage(fieldMappings)
        arcpy.Merge_management(inputs= r_plin,output="C:/tmp.gdb/tmp_Polyline2",field_mappings= fmap)

 

 

hi @BlakeTerhune above is the code i'm using, i forgot to say i'm using it in an python toolbox in arc catalog

thanks

 

Stu

0 Kudos
BlakeTerhune
MVP Regular Contributor

@StuartMoore wrote:

i'm using it in an python toolbox in arc catalog


What are the parameters in the toolbox?

0 Kudos
StuartMoore
Frequent Contributor

the only parameters are in input folder which contains the shp files and an output folder for where the merged gdb is placed

 

Stu

0 Kudos
StuartMoore
Frequent Contributor

i've been trying a few other ways like mergeing 5 files at a time but i now get this error

StuartMoore_0-1704728659844.png

i've even increased the field lengths and set the field map lengths to only use the first 50 characters (from my basic understanding)

StuartMoore_1-1704728730406.png

 

0 Kudos