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,弹出添加脚本对话框:

Arcpy 在ArcToolbox里的使用_第1张图片

下一步,选择脚本文件:

Arcpy 在ArcToolbox里的使用_第2张图片

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

Arcpy 在ArcToolbox里的使用_第3张图片


Arcpy 在ArcToolbox里的使用_第4张图片


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

Arcpy 在ArcToolbox里的使用_第5张图片



注意:

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

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

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


你可能感兴趣的:(ArcGISAssemble,Programming,language)