5

I would like to be able to update a load of pdf and jgeg maps once the data has been updated. Currently people have to open each mxd and export the map in each format. I've written a short python script that will export the current mxd. This works well:

##export current mxd to pdf and jpeg
mxd = arcpy.mapping.MapDocument("CURRENT")
mxd.save()
filename = mxd.filePath.split("\\")[-1].split(".")[0]
path = '\\\\main.corp.local\\E-GB$\\Home\\4\\J042\\Documents\\PWISE' + "\\" +filename
arcpy.mapping.ExportToPDF(mxd, path + '.pdf')
arcpy.mapping.ExportToJPEG(mxd, path + '.jpg',"PAGE_LAYOUT", 400,500,300)

This doesnt save all that much time though because someone still needs to open all the mxds and run it. I've therefore written this to run on each mxd:

##export current mxd to pdf and jpeg
import arcpy, os
#mxd = arcpy.mapping.MapDocument("CURRENT")
for root, dirs, files in os.walk(r"\\main.glb.corp.local\EP-GB$\Home\ABZ\4\J0422414\Desktop\EXPORTMXD"):

        for f in files:
            if f.endswith(".mxd"):
                mxdfile = root + '\\' + f
                mxd = arcpy.mapping.MapDocument(mxdfile)
                mxd.save()
                filename = mxd.filePath.split("\\")[-1].split(".")[0]
                path = '\\\\main.corp.local\\E-GB$\\Home\\4\\J042\\Documents\\PWISE' + "\\" +filename
                arcpy.mapping.ExportToPDF(mxd, path + '.pdf')
                arcpy.mapping.ExportToJPEG(mxd, path + '.jpg',"PAGE_LAYOUT", 400,500,300)
            else:
                print f

The weird problem here is that when there is a table in the layout view of the lap (as in attribute table menu > Add Table to Layout) it will not show - there is just a white space. This problem occurs both on the pdf and the jpeg

Does anyone know either if there is a solution to this export bug, or if I can adjust my script to open and close each mxd, running the relevant part of the script from within it? because it seems to work if the mxd is open

  • Have you tried explicitly setting all the parameters in the ExportToPDF command? It's possible that your MXD environment has some export settings that allow the script to export properly, but they don't get set the way you need them with the default command settings. desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-mapping/… – alexGIS May 12 '16 at 16:23
3

After some searching, it seems like this has been a 'known' issue/limitation since about 2012, unfortunately. See here: https://geonet.esri.com/thread/60621. The answer suggested some plugins to add the functionality.

An alternative for you, is to build your own table every time your script opens. This requires having a template graphic elements for a vertical and horizontal line, and a template text element in your document. Essentially you copy these templates to build your table and values.

There is an example with code on this help page: http://desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-mapping/graphicelement-class.htm

3

I have just replicated the problem, I too am unable to see the table in a page layout if I run the script outside an active mxd. I was using the very latest 10.4, so it appears to be a bug. You would need to contact ESRI directly to log this. I had also tried various combinations of other parameters for ExportToPDF().

Now here is an alternative way...

It's a part of ArcMap I don't use ever and that is the reporting tools. If you go to menu option View > reports you can create some nicely formatted reports. There are many options to tweak the look of the final report. Eventually you can click on the Add report to Layout button.

Running a script outside the mxd I was able to see my layout with map and report table.

There is guidance in the help file that talks you through the process of creating a report.

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.