problem with python code exporting to png with time enabled layer

933
2
04-03-2012 11:40 AM
LeilaHashemi
New Contributor
Hello
I'm using the ESRI sample code to export a mxd to a series of .PNG files. I set all parameters e.g. Startime, endtime.. etc. When I use the time slider, the changes on map appear correctly (different maps for different time-steps), But when I export it using the python code it create a series of PGN of the same map (it seems like pgns are several copies of the original map).

I don't know why it works in ArcMap but not when exporting. Any help would be greatly appreciated.

Thank you


import arcpy, datetime
mxd = arcpy.mapping.MapDocument(r"D:\project3.mxd")
df = arcpy.mapping.ListDataFrames(mxd,"layers")[0]
df.time.resetTimeExtent()
df.time.timeWindowUnits = "days"
df.time.timeWindow = 0
df.time.currentTime = datetime.datetime(1905, 06, 26)
endTime = datetime.datetime(1905, 07, 4)
interval = datetime.timedelta (days=2)
while df.time.currentTime <= endTime:
    fileName = str(df.time.currentTime).split(" ")[0] + ".png"
    arcpy.mapping.ExportToPNG(mxd, r"D:\\" + fileName,df)
    df.time.currentTime = df.time.currentTime + interval
    print fileName
del mxd
Tags (2)
0 Kudos
2 Replies
MathewCoyle
Frequent Contributor
Have you tried an arcpy.RefreshActiveView()?
0 Kudos
JohnLister
New Contributor

Hi I had a similar issue, and solved it, I was working from my personal machine and using an MXD I created from one of our GIS Servers, and saved it to a Shared Network location. When running the script, it produced the PNGs exactly how you described. When I then ran it from the  machine where the MXD, data and python script lived it produced the PNGs with the layers changing per time interval.

0 Kudos