arcgis10.0及以上版本,使用arcpy加载在arctoolbox中批量删除同一图层

代码:

#coding=gbk
#author:杨勇
#qq:1874445373

import arcpy,os,random,arcpy.mapping as mapping
MXD_Path = arcpy.GetParameterAsText(0)	#MXD文档所在目录
Del_Layer = arcpy.GetParameterAsText(1)		#所需删除图层的名称

x = random.randint(0,88888)
y =  'remove_layer' + str(x)
file_path = os.path.join(MXD_Path,y)
os.mkdir(r'%s'%file_path)

for root,dirs,files in os.walk(r'%s'%MXD_Path):
	for file in files:
		if file[-4:].lower() == '.mxd':
			path = os.path.join(MXD_Path,file)
			mxd = arcpy.mapping.MapDocument(r'%s'%path)
			df = arcpy.mapping.ListDataFrames(mxd)[0]
			lyrs = arcpy.mapping.ListLayers(mxd,'',df)
			for lyr in lyrs:
				if lyr.name == '%s'%Del_Layer:
					arcpy.mapping.RemoveLayer(df,lyr)
					mxd.saveACopy(os.path.join(file_path,file))
				else:
					print'yy'

转载自:https://blog.csdn.net/qq_35515661/article/details/80849105

You may also like...