# Script to use Layers in MXD source file paths to locate and redefine projections
import arcpy, glob, os, sys, arcgisscripting
mxd = arcpy.mapping.MapDocument("N:MXDs_ThomaKLMXD GPS ValvesGPS_Shapefile_Paths.mxd")
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.supports("DATASOURCE"):
print lyr.dataSource
from arcpy import env, mapping
path = lyr.dataSource
env.workspace = path
env.overwriteOutput = True
print 'Reading files from ' + path
sr = arcpy.SpatialReference(103133)
x=0
z=x+1
NoProjCount=0
FileList= arcpy.mapping.ListLayers(lyr)
for lyr in FileList:
desc = arcpy.Describe(lyr)
SR = desc.spatialReference
if SR.name == "Unknown":
print "Projection of " + str(lyr) + " is " + SR.name + " so defining projection."
f = open('NoProjection.txt', 'a')
f.write(str(lyr)+"n")
f.close()
arcpy.DefineProjection_management(lyr, sr)
NoProjCount=NoProjCount+1
else:
print lyr + " is projected " + str(SR.name)
so I have a script that works, but it only defines the projection for the very last Layer in the MXD and not the entire list of layers (there are around 50). I can tell I am missing something but I am not sure what. below is what the NoProjection.txt file has stored in it.
Valves.shp GPS PointsDataCollectedLater-ValvesValve_GPS Points GPS
PointsDataCollectedLater-ValvesValve_GPS Points GPS
PointsDataCollectedLater-ValvesValve_GPS Points GPS
PointsDataCollectedLater-ValvesValve_GPS Points GPS
PointsDataCollectedLater-ValvesValve_GPS Points GPS
PointsDataCollectedLater-ValvesValve_GPS Points GPS
PointsDataCollectedLater-ValvesValve_GPS Points GPS
PointsDataCollectedLater-ValvesValve_GPS Points