Hi everybody,
Working with ArcGIS 10.4, ArcInfo Licence
I am writing an arcpy script to set up a process for map automation. The user will design a map layout how they like and then use that layout to iterate through a list of rasters and export to pdf. I have pre-programmed certain text elements and one legend element to be dynamic and change as the rasters are added/removed from the layout.
My issue is with the legend element and style item. The user will add a legend and determine the item style of the raster layer using the legend wizard. I'd like my arcpy script to read what that style item type is and apply it to the next raster that is added to the map. I've been searching for ideas on how to 'describe' or 'get' the style item, but I can't find and arcpy method (and I'm way too novice to figure out the pure python way). I think I have to read the style item path name. I assume the information I need is floating around there somewhere because the legend wizard needs to know what the file path is rights?!
Does anyone have an idea of where to find an answer of what type of command I'm looking for? (even a search keyword would be useful!)
Below is a snippet of my script combined with how I want it to work (legend style item file variable). Also included is a screenshot of the tool and the map layout with the dynamic elements. These are works in progress!
Thanks,
Natasha
import arcpy
from arcpy import env
import arcpy.mapping as mp
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
legendItemStyleFile =
for raster in rasterFileName:
rasterLayer = mp.Layer(raster)
rasterLayer.visible = True
rasterSplit = re.split("[.,_?:]+", str(raster))
rasterFWI = rasterSplit[0]
rasterDate = rasterSplit[1]
rasterFileType = rasterSplit[2]
if labelDate == 'true':
arcpy.AddMessage("layer date: " + rasterDate)
textDate = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "textDate")[0]
textDate.text = rasterDate
if labelHeader == 'true':
textHeader = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "textHeader")[0]
textHeader.text = rasterFWI.upper()
legend = arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT")[0]
styleItem = arcpy.mapping.ListStyleItems("USER_STYLE", "Legend Items", legendItemStyleFile)[0]
legend.updateItem(lyr, styleItem)
arcpy.RefreshTOC()
arcpy.RefreshActiveView()