Select to view content in your preferred language

ARCPY and lyrtime

344
0
09-12-2023 05:57 AM
Labels (3)
Davec43
Regular Contributor

I do not understand where to insert my variables. 

import arcpy
lyrFile = arcpy.mp.LayerFile(r'C:\Projects\Time\ShipPositions.lyrx')
for lyr in lyrFile.listLayers():
    if lyr.supports('TIME'):
        if lyr.isTimeEnabled:
            lyrTime = lyr.time
            startTime = lyrTime.startTime
            endTime = lyrTime.endTime
            timeDelta = endTime - startTime
            print(f"Layer: {lyr.name}")
            print(f"  Start Time: {str(startTime.strftime('%m-%d-%Y'))}")
            print(f"  End Time:   {str(endTime.strftime('%m-%d-%Y'))}")
            print(f"  Time Extent: {str(timeDelta.days)} days")
        else:
            print("No time properties have been set on the layer")
    else:
        print("Time is not supported on this layer")

My variables are event_start and event_end but whenever I insert them I get an error.

import arcpy
lyrFile = arcpy.mp.LayerFile(r'\\file\file.lyrx')
for lyr in lyrFile.listLayers():
    if lyr.supports('TIME'):
        if lyr.isTimeEnabled:
            lyrTime = lyr.time
            startTime = lyrTime.event_start
            endTime = lyrTime.event_end
            timeDelta = endTime - startTime

 

 

0 Kudos
0 Replies