1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# ---------------------------------------------------------------------------
# Purpose : SaveAsMxd
# Author :gisweis
# Date :2016.4.17
# Version : ArcGIS 10.X
# Email :gisweis
# Notes :
# ---------------------------------------------------------------------------
import sys
#
#reload(sys)
#sys.setdefaultencoding( "utf-8" )
import arcpy
import
string
import os
try
:
path=arcpy.GetParameterAsText(0)
out
=arcpy.GetParameterAsText(1)
ver=arcpy.GetParameterAsText(2)
for
root,dirs,files
in
os.walk(path):
for
afile
in
files:
if
afile[-4:].lower() ==
'.mxd'
:
print root + os.sep + afile
print
out
+ os.sep + afile
mxd = arcpy.mapping.MapDocument(root + os.sep + afile)
mxd.saveACopy(
out
+ os.sep + afile,ver)
except arcpy.ExecuteError:
print arcpy.GetMessages()
|
关键点在于:
1.遍历mxd文件,使用了os.walk;
2.调用arcpy的另存为文档函数saveACopy。
参数是通过arcpy.GetParameterAsText来获取的,主要是为了制作python脚本工具(也可以写成固定路径,来执行python),制作方法可参考:
http://www.cnblogs.com/liweis/p/4252596.html
本文转自我也是个傻瓜51CTO博客,原文链接:http://www.cnblogs.com/liweis/p/5417802.html ,如需转载请自行联系原作者