Pergunta

I'm currently trying to use ArcPy mapping with the intent to create 20 - 30 maps automatically instead of creating them manually one-by-one. The issue is that nothing happens, and no errors are yielded when I implement the code. I'm trying to accomplish the following:

  • Make the symbology of each layer as "GRADUATED_COLORS" and the same symbology as the one layer I have already visualized.
  • Have the class break values for each layer be based on natural breaks.
  • Then later save each as a JPEG

Below is the code I am doing this in the ArcMap 10.2 python window. Any help would be great.

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.ListDataFrames(mxd) [0]
lyrs = arcpy.mapping.ListLayers(mxd, df)
lyrFile = arcpy.mapping.Layer("C://Users/Me/Desktop/Fires_Global_ALL/sep03_12_Grid10min_asia.shp")

The lyr file is the one I have visualized in the ArcMap with symbology I want.

for lyr in lyrs:
    arcpy.mapping.UpdateLayer( df, lyr, lyrFile)
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
Foi útil?

Solução

Two problems that I can see.\

First, df = arcpy.ListDataFrames(mxd)[0] needs to be arcpy.mapping.ListDataFrames(mxd)[0]

Secondly and probably the main issue, arcpy.mapping.ListLayers(mxd, df) is currently passing df as the wildcard, see the following syntax:

ListLayers (map_document_or_layer, {wildcard}, {data_frame})

You'll need to put in an additional blank wildcard arg ie arcpy.mapping.ListLayers(mxd, "", df) to return all the layers in the dataframe as expected.

See http://resources.arcgis.com/en/help/main/10.2/index.html#//00s30000002n000000

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top