Created
March 1, 2018 16:15
-
-
Save mu88/f893b7ac981726868a4a189216830acb to your computer and use it in GitHub Desktop.
ArcPy - Detect Layers with Joins in MXD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import arcpy, codecs, csv, os | |
mxd_folder = "C:\\temp\\MXD" | |
output = "C:\\temp\\results.csv" | |
f = codecs.open(output, "w", encoding="utf-8") | |
f.write("MXD;Layer;Result\n") | |
for file in os.listdir(mxd_folder): | |
if file.endswith(".mxd"): | |
mxd = os.path.join(mxd_folder, file) | |
mxd_filename = os.path.splitext(file)[0] | |
map_document = arcpy.mapping.MapDocument(mxd) | |
for lyr in arcpy.mapping.ListLayers(map_document): | |
layer_has_join = False | |
layer_name = lyr.name | |
if lyr.isGroupLayer: | |
f.write(mxd_filename + "; " + layer_name + "; Group layer (no joins)\n") | |
continue | |
if lyr.isRasterLayer: | |
f.write(mxd_filename + "; " + layer_name + "; Raster layer (no joins)\n") | |
continue | |
layer_description = arcpy.Describe(lyr) | |
if not hasattr(layer_description, "fields"): | |
f.write(mxd_filename + "; " + layer_name + "; Could not check layer\n") | |
continue | |
fields = layer_description.fields | |
for field in fields: | |
fieldname = field.name | |
if fieldname.find(lyr.datasetName) > -1: | |
layer_has_join = True | |
break | |
if layer_has_join: | |
f.write(mxd_filename + "; " + layer_name + "; Has join\n") | |
else: | |
f.write(mxd_filename + "; " + layer_name + "; No join detected\n") | |
f.close() | |
print "Completed" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment