import arcpy, glob, os path = r"C:\Users\Documents\GIS\Drawings\Revisions 06042012" mxdList = glob.glob(path + "\*.mxd") for mxd in mxdList: mxd = arcpy.mapping.MapDocument(mxd) print mxd layers = arcpy.mapping.ListLayers(mxd,"Local Wildlife Sites") print layers for layer in layers: defquery = '"LWS_STATUS"' + " = 'pLWS'" print defquery layer.definitionQuery = defquery mxd.save()
import arcpy, os workspace = r"C:\tmp\MapProjects" try: for filename in os.listdir(workspace): fullPath = os.path.join(workspace,filename) if os.path.isfile(fullPath): basename, extension = os.path.splitext(fullPath) if extension.lower() == '.mxd': mxd = arcpy.mapping.MapDocument(fullPath) #here build your definition query as STRING eg.: defQuery = '"OBJECTID" < 100' #Replace YourLayerName with the layer name (String) which will be changed for myLayer in arcpy.mapping.ListLayers(mxd, 'YourLayerName'): myLayer.definitionQuery = defQuery mxd.save() except: arcpy.GetMessages() del mxd, myLayer
from arcpy import mapping import arcpy mxd = mapping.MapDocument("CURRENT") layers = mapping.ListLayers(mxd) for layer in layers: layer.definitionQuery = "<FIELD> = '" + sql + "'" del layer mxd.save() del layers del mxd
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.