jameshaworth21

Dynamic time text using python...

Discussion created by jameshaworth21 on Apr 2, 2012
Hi all,

I was wondering if anyone might be able to help me. I'm creating an animated map that consists of four data frames so I'm using Python as the time slider can only deal with one frame at a time. I've inserted a dynamic text element on the layout to display the data frame time:

<dyn type="dataFrame" name="Current_TT" property="currentTime" emptyStr="[off]"/> GMT

The problem is that when I see this element in layout view, it displays "DD/MM/YYYY HH:MM:SS" whereas when I create the .bmp images using a python script the element displays "DD/MM/YYYY HH:MM:SS to DD/MM/YYYY HH:MM:SS". The date and time in each are exactly the same. My python script is as follows:

import arcpy
mxd = arcpy.mapping.MapDocument(r"fpath\filename.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Current_TT")[0]
df2 = arcpy.mapping.ListDataFrames(mxd, "5min_TT")[0]
df3 = arcpy.mapping.ListDataFrames(mxd, "15min_TT")[0]
df4 = arcpy.mapping.ListDataFrames(mxd, "30min_TT")[0]

df.time.currentTime = datetime.datetime(2010, 11, 05,  6, 0, 0)
df2.time.currentTime = df2.time.startTime
df3.time.currentTime = df3.time.startTime
df4.time.currentTime = df4.time.startTime
interval5 = datetime.timedelta(minutes=5)
interval15 = datetime.timedelta(minutes=15)
interval30 = datetime.timedelta(minutes=30)

i = 1
j = 1

endTime = datetime.datetime(2010, 11, 05,  21, 0, 0)
while df.time.currentTime <= endTime:
    if i == 4:
        df3.time.currentTime = df3.time.currentTime + interval15
        i = 1
    if j == 7:
        df4.time.currentTime = df4.time.currentTime + interval30
        j = 1
    fileName = str(df.time.currentTime)
    fileName = fileName[0:10] + "_" + fileName[11:13] + "_" + fileName[14:16] + ".bmp"
    arcpy.mapping.ExportToBMP(mxd, r"C:\Documents and Settings\ucesjah\My Documents\Dropbox\ArcGIS\GISRUK\test_images\\" + fileName)
    df.time.currentTime = df.time.currentTime + interval5
    df2.time.currentTime = df2.time.currentTime + interval5
    i = i+1
    j=j+1
del mxd

I've checked what each of the df.time.currentTime values is within the code and they are all single dates. I can't figure out where the "to DD/MM/YYYY HH:MM:SS" is coming from! Please help!

Thanks,

James

Outcomes