I have a python script that finds the feature class with the highest count for a field called 'SUM_USER_VisitCount' and then creates the symbology I specify. What I then want to do is save this feature class as a lyrx file, but the code I have for this seems to get skipped over. Can someone help me figure out what I'm doing wrong?
Here is a section of my code (let me know if you need to see the whole code):
<SPAN class="comment token">### get key for dictionary item with the highest value</SPAN>
highest_count_layer <SPAN class="operator token">=</SPAN> max<SPAN class="punctuation token">(</SPAN>results_dict<SPAN class="punctuation token">,</SPAN> key<SPAN class="operator token">=</SPAN>results_dict<SPAN class="punctuation token">.</SPAN>get<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>highest_count_layer<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>results_dict<SPAN class="punctuation token">[</SPAN>highest_count_layer<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#print(results_dict)</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> searchCursor<SPAN class="punctuation token">:</SPAN>
Symbology_Layer <SPAN class="operator token">=</SPAN> highest_count_layer
sym <SPAN class="operator token">=</SPAN> Symbology_Layer<SPAN class="punctuation token">.</SPAN>symbology
<SPAN class="keyword token">if</SPAN> hasattr<SPAN class="punctuation token">(</SPAN>sym<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'renderer'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> sym<SPAN class="punctuation token">.</SPAN>renderer<SPAN class="punctuation token">.</SPAN>type <SPAN class="operator token">==</SPAN> <SPAN class="string token">'SimpleRenderer'</SPAN><SPAN class="punctuation token">:</SPAN>
sym<SPAN class="punctuation token">.</SPAN>updateRenderer<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'GraduatedColorsRenderer'</SPAN><SPAN class="punctuation token">)</SPAN>
sym<SPAN class="punctuation token">.</SPAN>renderer<SPAN class="punctuation token">.</SPAN>classificationField <SPAN class="operator token">=</SPAN> <SPAN class="string token">'SUM_USER_VisitCount'</SPAN>
sym<SPAN class="punctuation token">.</SPAN>renderer<SPAN class="punctuation token">.</SPAN>breakCount <SPAN class="operator token">=</SPAN> <SPAN class="number token">5</SPAN>
sym<SPAN class="punctuation token">.</SPAN>renderer<SPAN class="punctuation token">.</SPAN>colorRamp <SPAN class="operator token">=</SPAN> p5<SPAN class="punctuation token">.</SPAN>listColorRamps<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Orange-Red (Continuous)'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token">### Remove decimal places from labels</SPAN>
<SPAN class="keyword token">if</SPAN> sym<SPAN class="punctuation token">.</SPAN>renderer <SPAN class="operator token">==</SPAN> <SPAN class="string token">"GraduatedColorsRenderer"</SPAN><SPAN class="punctuation token">:</SPAN>
breaks <SPAN class="operator token">=</SPAN> sym<SPAN class="punctuation token">.</SPAN>renderer<SPAN class="punctuation token">.</SPAN>classBreaks
<SPAN class="keyword token">for</SPAN> b <SPAN class="keyword token">in</SPAN> breaks<SPAN class="punctuation token">:</SPAN>
b_int <SPAN class="operator token">=</SPAN> b<SPAN class="punctuation token">.</SPAN>label<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">7</SPAN><SPAN class="punctuation token">]</SPAN>
b<SPAN class="punctuation token">.</SPAN>label <SPAN class="operator token">=</SPAN> b_int
<SPAN class="comment token">### Thousands Separators in labels</SPAN>
<SPAN class="keyword token">def</SPAN> FindLabel <SPAN class="punctuation token">(</SPAN>b<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">return</SPAN> <SPAN class="string token">"{:,}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>float<SPAN class="punctuation token">(</SPAN>b<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
Symbology_Layer<SPAN class="punctuation token">.</SPAN>symbology <SPAN class="operator token">=</SPAN> sym
p5<SPAN class="punctuation token">.</SPAN>save<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">### Where lyrx will be saved</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"E:\arcGIS_Shared\Python\Symbology Layers"</SPAN>
<SPAN class="comment token">### Set local variables</SPAN>
in_layer <SPAN class="operator token">=</SPAN> Symbology_Layer
out_layer_file <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"E:\arcGIS_Shared\Python\Symbology Layers\SGF_CumulativeSymbology.lyrx"</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>management<SPAN class="punctuation token">.</SPAN>SaveToLayerFile<SPAN class="punctuation token">(</SPAN>in_layer<SPAN class="punctuation token">,</SPAN> out_layer_file<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"ABSOLUTE"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Lyrx file saved'</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>