enableTime() in ArcPy throws a RuntimeError. But if you manually go to the properties and enable the time filter in ArcGIS Pro, then disable it, enableTime() works.
- Open a new ArcGIS Pro project with a new map
- Add the layer with time data to the map
- Open a Python window and run the following:
aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps()[0]
m.listLayers()[0].enableTime()It gives the following error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_mp.py", line 992, in enableTime
return convertArcObjectToPythonObject(self._arc_object.enableTime(*gp_fixargs((startTimeField, endTimeField, autoCalculateTimeRange, timeDimension), True)))
RuntimeError
In the Contents pane, right click the layer that was added -> Properties -> Time -> Filter layer contents based on attribute values -> OK.
The map refreshes and a time slider is visible. Go to properties and disable the time filter again.
Back in the Python window, run
m.listLayers()[0].enableTime()
It successfully enables the time filter with no errors.
Relevant documentation: https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/layertime-class.htm
I think this can't be a problem with the data I am using, because clearly it can filter by time when I enable it manually. Is there a step that I missed in ArcPy? Thanks