Select to view content in your preferred language

Making an Exporting Toolbox

619
4
05-22-2013 10:03 AM
MaryM
by
Deactivated User
I made a script for toolbox that works fine for exporting PDFs of all MXDs in a folder to another folder.  I don't have any settings optional.  I cannot choose options other than PDF.  How do I make a drop down in ArcToolbox so someone can choose the export type, like PDF, JPEG, etc?


This is my export to PDF script for my toolbox:

#Export standard maps to PDFs
#Written using ArcGIS 10 and Python 2.6.5


import arcpy, os

#Read input parameter from user.
path = arcpy.GetParameterAsText(0)

#Write MXD names in folder to txt log file.
writeLog=open(path+"\FileListLog.txt","w")
for fileName in os.listdir(path):
    fullPath = os.path.join(path, fileName)
    if os.path.isfile(fullPath):
        basename, extension = os.path.splitext(fullPath)
        if extension == ".mxd":
            writeLog.write(fullPath+"\n")
            mxd = arcpy.mapping.MapDocument(fullPath)
            print fileName + "\n"
del mxd
print "Done"
writeLog.close()


exportPath =arcpy.GetParameterAsText(1)
MXDread=open(path+"\FileListLog.txt","r")
for line in MXDread:
    #Strip newline from line.
    line=line.rstrip('\n')
    if os.path.isfile(line):
        basename, extension = os.path.splitext(line)
        newName=basename.split('\\')[-1]
        if extension.lower() == ".mxd":
            print "Basename:" +newName
            mxd = arcpy.mapping.MapDocument(line)
            newPDF=exportPath+"\\"+newName+".pdf"
            print newPDF
            arcpy.mapping.ExportToPDF(mxd,newPDF)
            print line + "Export Done"
MXDread.close()
item=path+"\FileListLog.txt"
os.remove(item)
del mxd



0 Kudos
4 Replies
JeffBarrette
Esri Regular Contributor
Define a parameter as a value list.

http://resources.arcgis.com/en/help/main/10.1/index.html#//001500000028000000

Once you do that, you will need extra logic in your code to call the correct arcpy.mapping export funtion.

Jeff
0 Kudos
MaryM
by
Deactivated User
I understand how to write the function of a value list I think, but then how do you set it up to be a input paramter like I did "path = arcpy.GetParameterAsText(0)" ?  I am new to programming, it may be a simple question.
0 Kudos
JeffBarrette
Esri Regular Contributor
You could have something like:

import arcpy
fileExt = arcpy.GetParameterAsText(0)  #Examples are [".JPG", ".PDF", ".TIF"]

newPDF=exportPath+"\\"+newName+fileExt

if fileExt == ".PDF":
  exportToPDF
elif fileExt == ".TIF":
  exportToTIF

etc


Jeff
0 Kudos
MaryM
by
Deactivated User
I get that, how do I assign the value list to the parameter or is that what the above does?
0 Kudos