0

I sm using ArcGIS Desktop (ArcMap) 10.8.1 and PyCharm 2020.3.3.

I'm trying to use a simple script to loop through a folder and export a PNG file for each MXD in the folder. The script works fine, and a file is successfully created for each MXD, but the elevation raster I have in each file is not shown in the exported PNG. I do not have this problem if I manually open the MXD and export the file to a PNG.

import arcpy
import os
arcpy.CheckOutExtension("Spatial")

inpath = r"D:\\Processing\\VermillionRiver\\"
outfolder = r"D:\\Processing\\Maps\\"
dirList = os.listdir(inpath)
print dirList

for item in dirList:
    mxd = arcpy.mapping.MapDocument(inpath + item)
    arcpy.mapping.ExportToPNG(mxd, outfolder + item[:-4], resolution = 200)
    del mxd

Here are the two different PNGs I get if I export manually from the MXD in ArcMap vs using the script above in PyCharm Manual export

Script generated output

The raster in the map is a 32 bit floating .tiff, is clipped to the dataframe, and is symbolized at 70% transparency.

4
  • What version of ArcGIS are you using?
    – GBG
    May 11 '21 at 20:18
  • I'm using ArcGIS 10.8.1 and PyCharm 2020.3.3
    – S Koenig
    May 11 '21 at 20:21
  • For starters this code should not run. Your file paths are wrong. Maybe you think it is running and exporting a PNG and you keep opening the same PNG file? stackoverflow.com/questions/2953834/windows-path-in-python
    – GBG
    May 11 '21 at 20:39
  • Code runs fine - I've tried varying the parameters for the ExportToPNG function and I delete the maps every time from the destination folder - each time the maps are created new, so they aren't the same map. What exactly isn't supposed to working in my code?
    – S Koenig
    May 11 '21 at 21:04
1

See this code that exports a PNG. You will need to change the paths back to your paths. I tried to keep it simple and comment it for you so that it makes sense.

import arcpy
arcpy.CheckOutExtension("Spatial")
inpath = "C:\\gTemp\\tester\\"
outfolder = "C:\\gTemp\\tester\\"
dirList = os.listdir(inpath)
print dirList

for item in dirList:
    #create an mxd object
    mxd = arcpy.mapping.MapDocument(inpath + item)
    #get the path to the mxd as a string
    mxdpathandname = mxd.filePath
    #Slice the mxd path and name at the .
    mxdpath = mxdpathandname.split(".")
    #get the part of the mxd without the .mxd    
    mxdpath = mxdpath[0]
    #split the string again to get the file name.
    mxdpath = mxdpath.split("\\")
    file_name = mxdpath.pop()
    file_name = file_name + ".png"
    arcpy.mapping.ExportToPNG(mxd, outfolder + "\\" + file_name, resolution = 200)
    del mxd
3
  • Not trying to offend or cause issues here, but this code just overwrites the same file in my folder and doesn't solve the issue I'm having - my issue is that the elevation raster isn't writing to the png from the map layout (the difference in the two pictures above). When I run my code, I get a folder with all my mxds exported to .pngs, but the elevation is missing. The code you provide doesn't help this unfortunately.
    – S Koenig
    May 11 '21 at 23:29
  • No offense taken. That's too bad. Maybe you have a corrupt MXD. Run MXD Doctor on the MXD, and then your code on your files. Se if that fixes things. If that does not help rename your normal.mxt file and try again.
    – GBG
    May 11 '21 at 23:44
  • Thanks - I will try that - appreciate your insight and patience.
    – S Koenig
    May 12 '21 at 0:19
0

The issue with the mxds not exporting the elevation background correctly was that the raster symbology Statistics were set to "From Current Display Extent" (a much larger extent DEM was being used for the maps than what each individual map extent is), and the ExportToPNG (and probably other export functions) doesn't seem work with/recognize that setting. Clipping the raster to each map boundary resulted in the maps exporting with the proper raster symbology.

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.