adding a list to arcpy.AddMessage

2555
2
Jump to solution
02-07-2012 04:53 AM
Michele
Occasional Contributor
I am struggling with a part of my script. I need to create an arcpy.AddMessage that says: Projected: with the list of feature classes that were projected in the loop, each separated by a comma and no trailing comma at the end

i.e. Projected: filename, filename, filename etc.

I've been at this for 3 days and know I am missing something stupid. Any help would be appreciated. Here is my code:

# Get the spatial reference of the Feature Class from folder A # Examine all Feature Classes in folder B and report if their # spatial references match the Feature Class in folder A  import arcpy arcpy.env.overwriteOutput = True  #set up the paths targetFC = arcpy.GetParameterAsText(0) folderToExamine = arcpy.GetParameterAsText(1)  #get spatial reference for the target feature class targetDescribe = arcpy.Describe(targetFC) targetSR = targetDescribe.SpatialReference targetSRName = targetSR.Name  # Get a list of my feature classes arcpy.env.workspace = folderToExamine listOfFCs = arcpy.ListFeatureClasses()  #Loop through the list of FCs for currentFC in listOfFCs:     #Read the spatial reference of the current one     currentFCDescribe = arcpy.Describe(currentFC)     currentFCSR = currentFCDescribe.SpatialReference     currentFCSRName = currentFCSR.Name          if currentFCSRName != targetSRName:         print "Spatial references don't match"     else:         print "Spatial references do match"        if currentFCSRName == targetSRName:         continue     else:        # Determine the new output feature class path and name         outCS = currentFC[:-4] +"_projected.shp"         #Reproject datasets that are different from target file         arcpy.Project_management(currentFC, outCS, targetSR)          #Create a message stating which files were projected         projFCs = outCS[:-14] +".shp"         projFCList = arcpy.ListFeatureClasses(projFCs)         x = ", ".join(projFCList) + ", "         arcpy.AddMessage("Projected " + str(x))
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MathewCoyle
Frequent Contributor
Something like this?
x = ', '.join(twpList)

View solution in original post

0 Kudos
2 Replies
MathewCoyle
Frequent Contributor
Something like this?
x = ', '.join(twpList)
0 Kudos
Michele
Occasional Contributor
Thanks for the reply Mathew!!  I actually revamped the bottom part of my code a little and was able to get it to work (although my arcpy.AddMessage is putting a "u" before each file name, which is annoying.  I know it means unformatted unicode string, but I can't figure out what part of my code is unformatted.

I created an empty list called "projFCList" outside of the loop and then changed the bottom part of the loop (I attached the whole loop section below):

    #Loop through the list of FCs  
for currentFC in listOfFCs:
        #print currentFC
        #Read the spatial reference of the current one
    currentFCDescribe = arcpy.Describe(currentFC)
    currentFCSR = currentFCDescribe.SpatialReference
    currentFCSRName = currentFCSR.Name
        #print currentFCSRName

    if currentFCSRName != targetSRName:
        print "Spatial references don't match"
    else:
        print "Spatial references do match"   
    if currentFCSRName == targetSRName:
            #skip
        continue
    else:
        outCS = currentFC[:-4] + "_projected.shp"
        arcpy.Project_management(currentFC, outCS, targetSR)
        projFCList.append(currentFC)

FCList = arcpy.AddMessage("Projected: " + str(projFCList).strip('[]'))