1

I am trying to put together my second tool so pretty new to this. What I want it to do is batch plot MXD's layouts to PDF found in a specific folder, without having to be in ArcMap. I'm trying to run the tool from ArcCatalog solely. When I run the Python script on its own in ArcCatalog and replace the parameter with the folder location, it works just fine. When I try to make it into a tool with the only input being the folder location, it doesn't work. All it does is pop up my script in notepad and says the process is complete.

Can someone tell me what I'm doing wrong?

import arcpy, os

ws = arcpy.GetParameterAsText(0)  

mxd_list = arcpy.ListFiles("*.mxd")

for mxd in mxd_list:

    current_mxd = arcpy.mapping.MapDocument(os.path.join(ws, mxd))
    pdf_name = mxd[:-4] + ".pdf"
    arcpy.mapping.ExportToPDF(current_mxd, pdf_name)

del mxd_list
3
  • 2
    do you need arcpy.env.workspace = ws
    – klewis
    Commented Feb 23, 2018 at 18:12
  • I believe if you print out the mxd_list you will see that it is empty which is why no PDF's are being created.
    – amasephy
    Commented Feb 23, 2018 at 18:16
  • That's exactly what I was missing, the workspace. Got it working, thanks!
    – vss031712
    Commented Feb 23, 2018 at 18:29

1 Answer 1

1

The "GetParameterAsText()" method generally is used from within a Script process, where you create a Toolbox saved in Catalog and inside that right click in your Catalog to Add -> Script. In the window that pops up, you can drive to a saved version of the .py file (which can be simply the code lines you have above). In the subsequent screen, you can add your parameter (the user will input a folder, and your Python script will use that to create the pdfs). See the example here:

enter image description here

Then, when you finish your script, it will be saved in the toolbox. When you double click it, it will provide the option of setting your folder Parameter, which your script will read on the back end:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.