Let say I have two variables.
InputMXD = parameters[0].valueAsText
PDF_Folder = parameters[1].valueAsText
I have my inputMXDs to have multivalues so I'll have around 10 mxds each time the script is run. I want to put the exported pdf's into different directory, but I want to use whatever the mxd name is. The input could be p:/mxds/oneexample.mxd and p:/mxds/onemoreexample.mxd and the output would be z:/pdfs/oneexample.pdf and p:/mxds/onemoreexample.pdf.
MXDList = arcpy.ListFiles(InputMXD)
for MXDPath in MXDList:
MXD = arcpy.mapping.MapDocument(MXDPath)
arcpy.mapping.ExportToPDF(MXD, PDF_Folder + )
Here's what I have to get me to the last line. I don't know how to add the original file name of the mxd to the outputted PDF.
Updated: It will run through it, but it doesn't output anything. The output folder is empty. I think there's something wrong with the loop. Here's what I now have in my loop.
MXDList = arcpy.ListFiles(InputMXD)
for MXDPath in MXDList:
MXD = arcpy.mapping.MapDocument(MXDPath)
outputPDF = os.path.basename(MXDPath).split('.')[0] + ".pdf"
arcpy.mapping.ExportToPDF(MXD, PDF_Folder + "\\" + outputPDF)
I tried the code below and still no dice. Here's what the results kicked back.
I'm not sure why it's saying the output is empty?
Update 2: I updated the code to this:
arcpy.env.overwriteOutput = True
arcpy.env.workspace = PDF_Folder
MXDList = arcpy.ListFiles('*.mxd')
for MXDPath in MXDList:
MXD = arcpy.mapping.MapDocument(MXDPath)
outputPDF = os.path.basename(MXDPath).split('.')[0] + ".pdf"
arcpy.mapping.ExportToPDF(MXD, PDF_Folder + "\\" + outputPDF)
I changed the workspace to PDF_Folder and it didn't kick back an error. It also didn't output any PDF files.
Also, here's how my parameters are setup at the top.
# First parameter
InputMXD = arcpy.Parameter(
displayName="Input MXDs",
name="InputMXD",
datatype="DEMapDocument",
parameterType="Required",
direction="Input",
multiValue=True)
# Second Parameter
PDF_Folder = arcpy.Parameter(
displayName="Output Folder for PDF",
name="PDF_Folder",
datatype="DEFolder",
parameterType="Required",
direction="Output")
Does my output need to be something besides a DEFolder datatype?
Update 3
Here's what my input looks like:
Input MXDs is a MapDocument that is a multiValue input.
Output Folder for PDF is a DEFolder output. I've tried strings, workspaces, folders. Nothing has worked. I know its something small making this really frustrating. I'm going basic to see if I can get just one mxd outputted to a pdf. Crawl before I can walk.
Update 4
I'm trying to run the command directly in ArcMap from the python window. Here is the kickback it's giving me.
Update 5
I have tried just running it in a small script to see if it worked with a file name. It does and it includes spaces, commas, periods, dashes and underscores. Here's the simple testing code that worked. I have no idea what isn't working.
import arcpy
doc = arcpy.mapping.MapDocument("Q://Field Data//6th P.M//COLORADO//6N65W//PROJECTS//6N-65W-12//HOLTON 6-65-12//BEP.mxd")
arcpy.mapping.ExportToPDF(doc, "C://temp//test2.pdf")
Best Answer
Give this a try to get the PDF name based on the input MXD lists name:
The parameters for the toolbox should look something like this: