arcgis10.0及以上版本,使用arcpy加载在arctoolbox中批量符号化

代码:

#coding:gbk
#author:yangyong
#会报错,不过不影响正常使用
import arcpy,os,re
import arcpy.mapping as mapping

import sys
reload(sys)
sys.setdefaultencoding("utf-8")

inputMxdPath = arcpy.GetParameterAsText(0)	#floder  eg:O:\arcgis_directory\MXD\RHYXT
outputMxdPath = arcpy.GetParameterAsText(1)	#floader  eg:eg:O:\arcgis_directory\MXD\RHYXT\print
fromLayer = arcpy.GetParameterAsText(2)		#string  eg: C:\yy.lyr
toLayer = arcpy.GetParameterAsText(3)		#string  eg:XZQ
sourceLayer = arcpy.mapping.Layer(r"%s"%fromLayer)

for root,dirs,names in os.walk(r"%s"%inputMxdPath):
	for name in names:
		if name[-4:].lower() == ".mxd":
			mxd = mapping.MapDocument(r"%s"%os.path.join(root,name))
			df  = mapping.ListDataFrames(mxd,"")[0]
			lyr = arcpy.mapping.ListLayers(mxd,toLayer,df)[0]
			arcpy.mapping.UpdateLayer(df,lyr,sourceLayer,True)
			newName = os.path.join(outputMxdPath,name)
			mxd.saveACopy(r"%s"%newName)
			arcpy.AddMessage("%s 另存为 成功"%name)

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

You may also like...