arcpy.mapping export not behaving as expected

418
2
12-01-2016 04:12 AM
Kah_SiongTan
New Contributor

Hi,

I was running arcpy.mapping tools and noted different behaviour running inside ArcMap python window and outside of it. The following is the partial code extract.

mxd = arcpy.mapping.MapDocument(mxdLocation)
df = arcpy.mapping.ListDataFrames(mxd)[0] 
lyr = arcpy.mapping.ListLayers(mxd,data_frame=df)[0]
currentLyrExtent=lyr.getExtent()  
df.extent = currentLyrExtent
currentLyrName=lyr.name
arcpy.RefreshActiveView()
arcpy.mapping.ExportToPNG(mxd,currentLyrName+".png","PAGE_LAYOUT")

This is the exported image after running in ArcMap Python window. Looks ok.

This is the exported image after running outside of ArcMap. The image only fills up 1/4 of the whole image frame.

What could be wrong?

0 Kudos
2 Replies
LukeWebb
Occasional Contributor III

When altering between inside / outside of ArcMAP, can you confirm you just change the line of code:

mxd = arcpy.mapping.MapDocument(mxdLocation)

to 
mxd = arcpy.mapping.MapDocument("CURRENT")



and everything else remains the same?
0 Kudos
Kah_SiongTan
New Contributor

Hi Luke,

There are no changes in codes when i alter between inside/outside of ArcMap. Both are as follows.

mxdLocation=r"c:\myfolder\mymap.mxd"
mxd = arcpy.mapping.MapDocument(mxdLocation)
0 Kudos