In ArcGIS 10.3, I had my shapefile list working in the script geoprocessing dialog window for the projection tool;
# Get the spatial reference
spatialRef = arcpy.Describe(template).spatialReference.name
# Loop through shapfiles in folder and reproject
for fc in fcList:
fcspatialRef = arcpy.Describe(fc).spatialReference.name
if fcspatialRef != spatialRef:
arcpy.Project_management(fc, outFolder + "\\" + fc, template)
# Print shapefile Project results
arcpy.AddMessage(fc)
# Return any errors
except:
arcpy.AddMessage(arcpy.GetMessages())
But when I add in copyFeatures_management because I want to copy the files which are already in the same projection and not reproject them, the dialog window changes and I lose my shapefile list in the geoprocessing dialog window;
# Get the spatial reference
spatialRef = arcpy.Describe(template).spatialReference.name
# Loop through shapfiles in folder and reproject
for fc in fcList:
fcspatialRef = arcpy.Describe(fc).spatialReference.name
if fcspatialRef != spatialRef:
arcpy.Project_management(fc, outFolder + "\\" + fc, template)
else:
arcpy.CopyFeatures_management(fc, outFolder + "\\" + fc)
# Print shapefile Project results
arcpy.AddMessage(fc)
# Return any errors
except:
arcpy.AddMessage(arcpy.GetMessages())
Can anyone please assist?
Solved! Go to Solution.
the solution is;
arcpy.AddMessage(fc)
arcpy.Project_management(fc, outFolder + "\\" + fc, template)
and not
arcpy.Project_management(fc, outFolder + "\\" + fc, template)
arcpy.AddMessage(fc)
I'm not sure what you mean by "geoprocessing dialog window". Do you mean the results window? What exactly do you see?
Yes Sephe, the results windows.
I used to see this;
And now I don't
Ah ok. Did the script perform the project and/or copy features? Well, anyway it's hard to tell from your formatting, but I think the script should be formatted like this:
for fc in fcList:
fcspatialRef = arcpy.Describe(fc).spatialReference.name
if fcspatialRef != spatialRef:
arcpy.Project_management(fc, outFolder + "\\" + fc, template)
else:
arcpy.CopyFeatures_management(fc, outFolder + "\\" + fc)
Notice the if/else statements are indented under the for statement, and the commands are indented under those.
Thanks Sephe, I couldn't work out why my script stopped working.
Ok, instead of printing out only the projected shapefiles (should be 6) in the list in the dialog window, it is printing both the projected and copied files (all 8 files).
Ok, try it like this:
# Loop through shapfiles in folder and reproject
for fc in fcList:
fcspatialRef = arcpy.Describe(fc).spatialReference.name
if fcspatialRef != spatialRef:
arcpy.Project_management(fc, outFolder + "\\" + fc, template)
# Print shapefile Project results
arcpy.AddMessage(fc)
else:
arcpy.CopyFeatures_management(fc, outFolder + "\\" + fc)
the solution is;
arcpy.AddMessage(fc)
arcpy.Project_management(fc, outFolder + "\\" + fc, template)
and not
arcpy.Project_management(fc, outFolder + "\\" + fc, template)
arcpy.AddMessage(fc)