I am trying to export a pdf for each mxd in a folder. So far for code I have:
import arcpy, os
Workspace = r"FilePath"
arcpy.env.workspace = Workspace
arcpy.env.overwriteOutput=True
for file in arcpy.ListFiles("*.mxd"):
mxd_path = os.path.join(Workspace,file)
mxd = arcpy.mapping.MapDocument(mxd_path)
outpdf = file + ".pdf"
arcpy.mapping.ExportToPDF(mxd,outpdf)
mxd.save()
I receive the error:
Runtime error
Traceback (most recent call last):
File "<string>", line 5, in <module>
File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\utils.py", line 182, in fn_
return fn(*args, **kw)
File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\mapping.py", line 1156, in ExportToPDF
layout.exportToPDF(*args)
AttributeError: PageLayoutObject: Error in executing ExportToPDF
I am confused as to why the ExportToPDF is failing.
AttributeError: PageLayoutObject
makes it seem like an issue with the MXD rather than your script. When I test your script as-is (other than replacing with an actual path) I get no errors at all, and it happily creates files withfilename.mxd.pdf
which while untidy and potentially confusing, shouldn't be the cause of this issuemxd.save()
in there? You're not modifying the MXD, so shouldn't need to save it