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