Enable Time for a layer using arcpy

5404
7
Jump to solution
09-03-2015 09:21 AM
IanIrmischer
New Contributor III

I have over 1000 feature classes that I am loading into a map document.  I have figured out how to automate this process in using Arcpy.  Each feature class has a field with datetime.  I can enable time on the layers one by one by right clicking on the layer once it is in arcmap and clicking the box "enable time on this layer". I would like to automate the process using arcpy.  Can anyone help?

Ian

0 Kudos
1 Solution

Accepted Solutions
IanMurray
Frequent Contributor

Hi Ian

I don't believe there is a direct way to do this with arcpy.mapping.Layer.  However, if you have a saved Layer file that does have time enabled, you should be able to use arcpy.mapping.UpdateLayerTime to update the time properties of the layers you are adding from an existing .lyr file.

see:(copy/paste) http://resources.arcgis.com/en/help/main/10.1/index.html#/UpdateLayerTime/00s300000064000000/

I'd test on a single layer first.

Ian M

View solution in original post

7 Replies
IanMurray
Frequent Contributor

Hi Ian

I don't believe there is a direct way to do this with arcpy.mapping.Layer.  However, if you have a saved Layer file that does have time enabled, you should be able to use arcpy.mapping.UpdateLayerTime to update the time properties of the layers you are adding from an existing .lyr file.

see:(copy/paste) http://resources.arcgis.com/en/help/main/10.1/index.html#/UpdateLayerTime/00s300000064000000/

I'd test on a single layer first.

Ian M

IanIrmischer
New Contributor III

Ian, Thanks very much for the help.  This method worked.  It might be nice for ESRI to build an arcpy tool in the future but this method works for my purposes.  I was able to load all the files via arcpy.  Then I enabled time on the 1st layer in the TOC.  Then I used arcpy to enable time in all the other layers via code below:

MXD = arcpy.mapping.MapDocument("CURRENT")

DF = arcpy.mapping.ListDataFrames(MXD)[0]

sourceLayer=arcpy.mapping.ListLayers(MXD,"",DF)[0]

updateLayer=arcpy.mapping.ListLayers(MXD,"",DF)

for layers in updateLayer:

    arcpy.mapping.UpdateLayerTime (DF,layers, sourceLayer)

IanMurray
Frequent Contributor

They are very hit and miss about what layer properties you can set with arcpy, and which ones you need ArcObjects to directly manipulate.  Luckily they had somewhat of a workaround for this particular scenario.

0 Kudos
DanPatterson_Retired
MVP Emeritus

This post is a duplicate of

https://community.esri.com/message/548340#548340

possible links are on that thread.  post and/or update in one thread, then share to spaces, don't just try again the next day

0 Kudos
IanMurray
Frequent Contributor

There was another duplicate over in python snippets Space.  I went ahead and shared with a few other Places

0 Kudos
IanIrmischer
New Contributor III

Thanks Ian. 

0 Kudos
IanIrmischer
New Contributor III

Apologies, I didn't know the protocol.

Ian

0 Kudos