Hello all -
I'm using ArcPro version 2.5.2. I want to change the symbology of a layer in my map using python. I'm developing and executing the code out of an ArcGIS Notebook. The layer was added to the map from a feature class geodatabase. I've followed the code examples in the ESRI documentation, but cannot produce results.
The code I've written will run without an error, but the updated symbology won't change/show in the map view. For example, if I "print" details of the layer's symbology after running my script, it will appear that it has been updated. However, the layer in the map view looks the same, and right clicking symbology on the layer shows the old parameters. This problem is not limited to a particular layer, but all the layers in my projects. Where am I going wrong? Any is help appreciated. Below is the generic code:
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="comment token"># define project</SPAN>
project_path <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"C:\Users\person\Desktop\folder\project.aprx"</SPAN>
p <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mp<SPAN class="punctuation token">.</SPAN>ArcGISProject<SPAN class="punctuation token">(</SPAN>project_path<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># specify map in project named "Map"</SPAN>
m <SPAN class="operator token">=</SPAN> p<SPAN class="punctuation token">.</SPAN>listMaps<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Map'</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"># specify layer in map named "polygons"</SPAN>
lyr <SPAN class="operator token">=</SPAN> m<SPAN class="punctuation token">.</SPAN>listLayers<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'polygons'</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"># access symbology of layer and change symbology to graduated colors</SPAN>
sym <SPAN class="operator token">=</SPAN> lyr<SPAN class="punctuation token">.</SPAN>symbology
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">'value'</SPAN>
sym<SPAN class="punctuation token">.</SPAN>classificationMethod <SPAN class="operator token">=</SPAN> <SPAN class="string token">'NaturalBreaks'</SPAN>
sym<SPAN class="punctuation token">.</SPAN>renderer<SPAN class="punctuation token">.</SPAN>breakCount <SPAN class="operator token">=</SPAN> <SPAN class="number token">10</SPAN>
<SPAN class="comment token"># save symbology back onto layer</SPAN>
lyr<SPAN class="punctuation token">.</SPAN>symbology <SPAN class="operator token">=</SPAN> sym
<SPAN class="comment token"># save project</SPAN>
p<SPAN class="punctuation token">.</SPAN>save<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>