I'm doing some programming work for a client and we can't seem to get the script tool to work on her end. It works perfectly on my end but when she tries it, it grinds away for a long time and then gives her an AttributeError: Invalid destination path. I asked what version of ArcMap she's using and she says 10.1. I'm using 10.3. Could the different versions be the cause of the problem?

import arcpy

inputList = arcpy.GetParameterAsText(0)
bckGrndLyrs = arcpy.GetParameterAsText(1)
pageRng = arcpy.GetParameterAsText(2)
outLoc = arcpy.GetParameterAsText(3)
exportDPI = arcpy.GetParameterAsText(4)

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]

for lyrs in arcpy.mapping.ListLayers(mxd, "", df):
    if lyrs.name in inputList:
        lyrs.visible = False
    elif lyrs.name in bckGrndLyrs:
        lyrs.visible = True  
        lyrs.visible = False

for inFC in arcpy.mapping.ListLayers(inputList, "", df):
    if inFC.name in inputList:
        arcpy.AddMessage("Activating " + inFC.name + " Layer")
        inFC.visible = True
        for titleItem in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
            if titleItem.name == 'EditedTitle':
                arcpy.AddMessage("...Changing title to " + inFC.name)
                titleItem.text = inFC.name 
                arcpy.AddMessage("......Exporting pages " + pageRng + " as PDF")    
            for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
                if str(pageNum) in pageRng:
                    mxd.dataDrivenPages.currentPageID = pageNum
                    blockName = mxd.dataDrivenPages.pageRow.Block
                    mxd.dataDrivenPages.exportToPDF(outLoc + "\\" + inFC.name + ".pdf", page_range_type="RANGE", page_range_string=pageRng, multiple_files="PDF_MULTIPLE_FILES_PAGE_NAME", resolution=exportDPI)
            arcpy.AddMessage(".........Deactivating " + inFC.name + " Layer")       
            inFC.visible = False

del mxd

Error that appears in Tool dialgog box

AttributeError: Invalid Destination Path

  • 2
    It's possible, depending on what your code does and what tools you're calling. However, it seems like you're writing to a location she cannot access. Could you post some code? – Fezter Jul 7 '16 at 4:28
  • 1
    I agree with @Fezter - sounds more like a path problem between machines rather than ArcPy between versions. I think of ArcPy 10.1 SP1 to 10.4 as being near identical and the main difference between 10.1 and 10.1 SP1 being the addition of ArcPy.da.Walk(). – PolyGeo Jul 7 '16 at 4:47
  • There we go, Fezter. I posted the code – S. Price Jul 7 '16 at 5:42
  • What is the full error message (with line number) when she runs this? – PolyGeo Jul 7 '16 at 6:09
  • 1
    My guess is that it doesn't like the outLoc variable. When you write the outputs, I suggest you use os.path.join from the os module. It's a much cleaner way to join paths. If you tested in a location like C:/temp you may not get the error. But if she is pointing to a nested folder she may. Also depends on what your parameter settings are. – Fezter Jul 7 '16 at 7:28

After looking at the code and the error you're getting, I think this can be pinned down to exporting the DDP PDFs. Python is trying to parse the outLoc path and failing because the backslashes are escaping and the full path isn't being read.

The way to fix this is to us the os.path module.

Insert the following in the top of your code:

import os

Then, at the end of your code, you can change the export DDP line to the following:

mxd.dataDrivenPages.exportToPDF(os.path.join(outLoc,(inFC.name + ".pdf")), page_range_type="RANGE", page_range_string=pageRng, multiple_files="PDF_MULTIPLE_FILES_PAGE_NAME", resolution=exportDPI)

Also, in your script tool parameters, the Data Type for the output location should be Folder. enter image description here

You may even get away with changing:

outLoc = arcpy.GetParameterAsText(3)


outLoc = arcpy.GetParameter(3)

But that might not be necessary.

  • I agree that os.path.join(outLoc,(inFC.name + ".pdf")) is a better solution. outLoc + "\\" + inFC.name + ".pdf" should work-print that to the geoprocessing window before the actual export to pdf and see what the path looks like? – GBG Jul 8 '16 at 17:06
  • So I tried the os.path module, and it works on her end. She didn't get the error but she says that it still grinds away for a very long time. The tool takes about 20-30 seconds to complete on my computer, but it took 18 hours last time she tried it on her computer. What could be causing that? She left it over night last night and it didn't give the error, but when she came back to work this morning it was still running. – S. Price Jul 15 '16 at 1:52
  • 1
    Any number of issues could be causing that. There are a lot of thing we don't know. Is she writing the files locally to her computer? Or to a network file system? Are you both working in a similar environment? Does she have write permissions to the location? I suggest you put some print statements throughout your code to confirm that it's getting to certain parts of your script. Or you could insert your code within a try/except statement and see if it's failing. None of this seems like it is within the scope of your original question, and I suggest you ask a new one and accept this one. – Fezter Jul 15 '16 at 2:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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