Skip to main content
3 of 5
edited tags
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

Using Arcpy.AddMessage() to list out all shapefiles that were converted in a folder

I currently have code that re-projects all my shapefiles in a folder based off an input shapefile that I select. I will attach the code below. The code runs fine, but I would like the message on the geoprocessor window to say "Projected feature1, feature2, feature3, etc"

I currently can only get the script to list: "Projected feature1" "Projected feature2" "Projected feature3"

Like this:

enter image description here

I need the result to be:

enter image description here

It's basically printing the message for each iteration of the loop but I need it to print each feature class selected. Hopefully that makes sense. Attached is my example script below.

import arcpy
folderLocation = arcpy.GetParameterAsText(0)
targetShapefile = arcpy.GetParameterAsText(1)

try:
    
    targetDescribe = arcpy.Describe(targetShapefile)
    targetSpatialRef= targetDescribe.spatialReference
    targetSpatialName = targetSpatialRef.Name
    arcpy.env.workspace = folderLocation
    featureList = arcpy.ListFeatureClasses()
    for fc in featureList:
        desc = arcpy.Describe(fc)
        spatialRef = desc.spatialReference
        fcName = spatialRef.Name
        
        
        if fcName != targetSpatialName:
            rootName = fc.replace(".shp", "")
            outfc = folderLocation + '\\' + rootName + "_Projected"
            outCS = targetSpatialRef
            arcpy.Project_management(fc, outfc, outCS)
            arcpy.AddMessage("Projected "+ fc)


except:
    print arcpy.GetMessages()
DEB
  • 305
  • 1
  • 10