Arcpy 在ArcToolbox里的使用

今天试验了一下python脚本在ArcToolbox里的使用

1、脚本,用的是esri的脚本,如下:

# Author:  ESRI
# Date:    July 5, 2010
# Version: ArcGIS 10.0
# Purpose: This script will export multiple map document layoutinto a single
#          output PDF file. The script is intended to run within a script tool.  There are two
#          parameters:
#               1) Select Map Documents to Append,
#               2) Output PDF.
#
#Notes: The order of the MXDs is based on how they are entered.  The MXD at the
#       top of the list is first followed by those below it.
import sys
reload(sys)
sys.setdefaultencoding('utf-8')

import arcpy, os, string

#Read input parameters from script tool
mxdList = string.split(arcpy.GetParameterAsText(0), ";")
outPDFpath = arcpy.GetParameterAsText(1)

#Create a new PDF object to store the results
outputPDF = arcpy.mapping.PDFDocumentCreate(outPDFpath)

#Loop through each MXD in the list, export, create a temporary PDF name,
# and append to final, output PDF
for mxdPath in mxdList:
    mxd = arcpy.mapping.MapDocument(mxdPath)
    PDFPath = mxdPath[:-4] + "_temp.pdf"
    arcpy.mapping.ExportToPDF(mxd, PDFPath)
    outputPDF.appendPages(str(PDFPath))


#Save the changes and open the result automatically   
outputPDF.saveAndClose()
os.startfile(outPDFpath)

#Remove variable reference to file
del outputPDF


2、在ArcCatalog里面新建一个Toolbox,如下图


3、右键单击新建的Toolbox, add->script,弹出添加脚本对话框:


下一步,选择脚本文件:


下一步,设置输入和输出参数:





Finish完整的工具箱中脚本的制作,界面如下:




注意:

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

这三句话一定要加,不然会出现如下的错误:

 UnicodeEncodeError: 'ascii' codec can't encode characters in position 3-6: ordinal not in range(128) 


评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值