# Script to use Layers in MXD source file paths to locate and redefine projectionsimport arcpy, glob, os, sys, arcgisscriptingmxd = arcpy.mapping.MapDocument("N:\MXDs\_ThomaKL\MXD GPS Valves\GPS_Shapefile_Paths.mxd")for lyr in arcpy.mapping.ListLayers(mxd): if lyr.supports("DATASOURCE"): print lyr.dataSourcefrom arcpy import env, mappingpath = lyr.dataSourceenv.workspace = pathenv.overwriteOutput = Trueprint 'Reading files from ' + pathsr = arcpy.SpatialReference(103133)x=0z=x+1NoProjCount=0FileList= 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.
أكثر...
أكثر...