UpdateLayerTime (arcpy.mapping)

Resumen

Provides the ability to update a layer's time properties for a layer in a map document (.mxd) by extracting time properties from a source layer.

Debate

The UpdateLayer function has the ability to only update a layer's symbology properties or update ALL layer properties, including time properties.

The UpdateLayerTime function allows you to update only the time properties of a layer and therefore won't overwrite other layer properties that you don't want to change.

The source_layer contains the time properies that you want to apply. It can either be a layer file on disk or a reference to another layer in a map document.

If you want to update the properties for a layer within a layer file, you must modify the properties of the layer in a map document first and then save the changes back to a layer file. See the Layer object's save or saveACopy methods and the code example below.

Sintaxis

UpdateLayerTime (data_frame, update_layer, source_layer)
ParámetroExplicaciónTipo de datos
data_frame

A reference to a DataFrame object that contains the layer to be updated.

DataFrame
update_layer

A Layer object representing an existing layer that will be updated.

Layer
source_layer

A reference to a Layer object that contains the information to be applied to the update_layer.

Layer

Ejemplo de código

UpdateLayerTime example 1

The following script will update a layer's time properties using a layer file. The layer called temperature is not time enabled. The time properties of a time-enabled layer file will be applied to the temperature layer.

import arcpy

mxd = arcpy.mapping.MapDocument(r"C:\Project\Temperature.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "World")[0]
lyr = arcpy.mapping.ListLayers(mxd, "temperature", df)[0]
lyrFile = arcpy.mapping.Layer(r"C:\Project\Data\Time\LayerWithTimeProperties.lyr")
arcpy.mapping.UpdateLayerTime(df, lyr, lyrFile)

# Save changes to a new MXD
mxd.saveACopy(r"C:\Project\Temperature2.mxd")
# Clean up variables
del mxd, df, lyr, lyrFile
UpdateLayerTime example 2

The following script is similar to the one above but saves the changes back out to a layer file.

import arcpy

mxd = arcpy.mapping.MapDocument(r"C:\Project\Temperature.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "World")[0]
lyr = arcpy.mapping.ListLayers(mxd, "temperature", df)[0]
lyrFile = arcpy.mapping.Layer(r"C:\Project\Data\Time\LayerWithTimeProperties.lyr") #orginally authored in ArcMap
arcpy.mapping.UpdateLayerTime(df, lyr, lyrFile)

# Save changes to a new Layer file
lyr.saveACopy(r"C:\Project\TemperatureWithTime.lyr")
# Clean up variables
del mxd, df, lyr, lyrFile
9/11/2013