ckeithcape

problem with python code exporting to png with time enabled layer

Discussion created by ckeithcape on Mar 8, 2011
Latest reply on Mar 8, 2011 by ckeithcape
Hi-
I'm using the ESRI sample code (modified below) to export a mxd to a series of .PNG files.  I'm having problems with the dynamic text associated with the layers.  In arcmap I can use the time slider and the text appears correctly - changing by 5 years for each .PNG.  But when I export it using the python code it changes the dynamic time text as  the time series advances - I think it may have something to do with leap years but I'm not sure.  In the .PNG files I'm displaying dynamic text ("time.date" format = "MMM yyyy") and what happens as the time series advances is that at first it shows correctly as Jan 1961 to Jan 1966, Jan 1966 to Jan 1971, Jan 1971 to Jan 1976 but then to Dec 1975 to Dec 1980 - should be Jan 1976 to Jan 1981.
 
I've tried hard coding the py.script using datetime.timedelta(days=1825) but I get similar problems.

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

here is the code.
import arcpy, datetime
mxd = arcpy.mapping.MapDocument(r"C:\GIS_data\mxds\ytf.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]
df.time.currentTime = datetime.datetime(1961,01,01)
while df.time.currentTime <= df.time.endTime + df.time.timeStepInterval:
    #An example str(newTime) would be: "2008-12-29 02:19:59"
    #The following line splits the string at the first - and takes the first
    #item in the resulting string. 
    fileName = "YF2_" + str(df.time.currentTime).split("-")[0] + ".png"
    arcpy.mapping.ExportToPNG(mxd, r"C:\GIS_data\media\ytf\\" + fileName)
    df.time.currentTime = df.time.currentTime + df.time.timeStepInterval
    print fileName
del mxd

Outcomes