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!
from arcpy import env
import arcpy.mapping as mp
# This is part of my script... I am envisioning something like.....
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)
legendItemStyleFile = #This is where I want to 'get' the style path
# currently in use by the item already in my legend.
# Do some stuff here to add the rasters in my Raster List,
# and to make a map based only on the rasters in the Raster List.
for raster in rasterFileName:
rasterLayer = mp.Layer(raster)
rasterLayer.visible = True
rasterSplit = re.split("[.,_?:]+", str(raster))
rasterFWI = rasterSplit
rasterDate = rasterSplit
rasterFileType = rasterSplit
#Changes the date label if the boolean is true
if labelDate == 'true':
arcpy.AddMessage("layer date: " + rasterDate)
#Date Text Element Change
textDate = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "textDate")
textDate.text = rasterDate
#Changes the header label if the boolean is true
if labelHeader == 'true':
textHeader = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "textHeader")
textHeader.text = rasterFWI.upper()
#Update the legend item with the style from my original raster (legendItemStyleFile variable).
legend = arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT")
styleItem = arcpy.mapping.ListStyleItems("USER_STYLE", "Legend Items", legendItemStyleFile)
#*** still have to write the export, turn off raster and turn on the next part of this script...