<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Using UniqueValuesSymbology Class at 10.1 in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/using-uniquevaluessymbology-class-at-10-1/m-p/159241#M12204</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I follow your way to update mxd,but ''sym.classLabels = labelList''cannot affect after i check the labelList in ArcMap10.1,in fact,there was not any change in mxd,what's wrong?Any help will be appreciated !&lt;/SPAN&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I just did something similar for a colleague.&amp;nbsp; Here is the complete code snippet.&amp;nbsp; Just like you suggest, I build two empty lists and append the unique values to them.&amp;nbsp; Note, I'm using the new da.SearchCursor at 10.1.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy

def int_if_you_can(x):
&amp;nbsp; return int(x) if x % 1.0 == 0 else x

#Reference layer and update to Unique Value renderer using layer file
mxd = arcpy.mapping.MapDocument("current")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
lyr100 = arcpy.mapping.ListLayers(mxd, "interval_100")[0]
lyrFile = arcpy.mapping.Layer(r"C:\Active\ArcPY\Users\SteveLynch\interval_100.lyr")
arcpy.mapping.UpdateLayer(df,lyr100,lyrFile)

#Apply source data to layer
sym = lyr100.symbology
sym.addAllValues()

#Generate unique list of lables
classList = []
labelList = []

with arcpy.da.SearchCursor(lyr100, ("mean_cont", "low_cont", "high_cont"), sql_clause=(None,"ORDER BY mean_cont")) as rows:
&amp;nbsp; for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; lowCont = str(int_if_you_can(row[1]))
&amp;nbsp;&amp;nbsp;&amp;nbsp; highCont = str(int_if_you_can(row[2]))
&amp;nbsp;&amp;nbsp;&amp;nbsp; if not lowCont + " - " + highCont in labelList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; classValue = in_if_you_can(row[0])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; classList.append(classValue)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; label = lowCont + " - " + highCont
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; labelList.append(label)

#Update layer with new label classes
sym.classValues = classList
sym.classLabels = labelList
arcpy.RefreshActiveView()
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Jeff&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 08:24:32 GMT</pubDate>
    <dc:creator>jiangjian</dc:creator>
    <dc:date>2021-12-11T08:24:32Z</dc:date>
    <item>
      <title>Using UniqueValuesSymbology Class at 10.1</title>
      <link>https://community.esri.com/t5/python-questions/using-uniquevaluessymbology-class-at-10-1/m-p/159239#M12202</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am playing around with the UniqueValuesSymbology class introduced at 10.1. It looks like the properties of the layer symbology is passed into python lists (i.e. classValues, classLabels)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I edited the script example from the help menu to update the classValues based on a list built from values in a field ('SMU') in a feature class. This works fine. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What I am struggling with is, after the class Values are updated, I want hard code the matching classLabels (or use a look up table) to update the label based on values in the classValue. So just an if statement to say something like. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp; if lyr.symbology.classValues == "M1":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.symbology.classLabels = "Test"&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I understand why this kind of is statement isn't working because the properties are python lists. So, I'm thinking I need to build 2 lists, one for the classValues and then one for the classLabels, but I'm just not sure how to go about it. Here's is my code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
import arcpy
mxd = arcpy.mapping.MapDocument(r"Z:\Test.mxd")
lyr = arcpy.mapping.ListLayers(mxd, "Soil Map Units_temp")[0]

smuList = []
rows = arcpy.da.SearchCursor(lyr, ["SMU"])
for row in rows:
&amp;nbsp; smuList.append(row[0])

if lyr.symbologyType == "UNIQUE_VALUES":
&amp;nbsp; lyr.symbology.classValues = smuList
&amp;nbsp; lyr.symbology.showOtherValues = False


# this is my pseudo code. In essence, this is what I want to do. Update the classLabel based on the values from classValues
&amp;nbsp; if lyr.symbology.classValues == "M1":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.symbology.classLabels = "Test"


&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any suggestions are welcome.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Jun 2012 15:32:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-uniquevaluessymbology-class-at-10-1/m-p/159239#M12202</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2012-06-13T15:32:13Z</dc:date>
    </item>
    <item>
      <title>Re: Using UniqueValuesSymbology Class at 10.1</title>
      <link>https://community.esri.com/t5/python-questions/using-uniquevaluessymbology-class-at-10-1/m-p/159240#M12203</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I just did something similar for a colleague.&amp;nbsp; Here is the complete code snippet.&amp;nbsp; Just like you suggest, I build two empty lists and append the unique values to them.&amp;nbsp; Note, I'm using the new da.SearchCursor at 10.1.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy

def int_if_you_can(x):
&amp;nbsp; return int(x) if x % 1.0 == 0 else x

#Reference layer and update to Unique Value renderer using layer file
mxd = arcpy.mapping.MapDocument("current")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
lyr100 = arcpy.mapping.ListLayers(mxd, "interval_100")[0]
lyrFile = arcpy.mapping.Layer(r"C:\Active\ArcPY\Users\SteveLynch\interval_100.lyr")
arcpy.mapping.UpdateLayer(df,lyr100,lyrFile)

#Apply source data to layer
sym = lyr100.symbology
sym.addAllValues()

#Generate unique list of lables
classList = []
labelList = []

with arcpy.da.SearchCursor(lyr100, ("mean_cont", "low_cont", "high_cont"), sql_clause=(None,"ORDER BY mean_cont")) as rows:
&amp;nbsp; for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; lowCont = str(int_if_you_can(row[1]))
&amp;nbsp;&amp;nbsp;&amp;nbsp; highCont = str(int_if_you_can(row[2]))
&amp;nbsp;&amp;nbsp;&amp;nbsp; if not lowCont + " - " + highCont in labelList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; classValue = in_if_you_can(row[0])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; classList.append(classValue)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; label = lowCont + " - " + highCont
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; labelList.append(label)

#Update layer with new label classes
sym.classValues = classList
sym.classLabels = labelList
arcpy.RefreshActiveView()
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:24:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-uniquevaluessymbology-class-at-10-1/m-p/159240#M12203</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2021-12-11T08:24:29Z</dc:date>
    </item>
    <item>
      <title>Re: Using UniqueValuesSymbology Class at 10.1</title>
      <link>https://community.esri.com/t5/python-questions/using-uniquevaluessymbology-class-at-10-1/m-p/159241#M12204</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I follow your way to update mxd,but ''sym.classLabels = labelList''cannot affect after i check the labelList in ArcMap10.1,in fact,there was not any change in mxd,what's wrong?Any help will be appreciated !&lt;/SPAN&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I just did something similar for a colleague.&amp;nbsp; Here is the complete code snippet.&amp;nbsp; Just like you suggest, I build two empty lists and append the unique values to them.&amp;nbsp; Note, I'm using the new da.SearchCursor at 10.1.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy

def int_if_you_can(x):
&amp;nbsp; return int(x) if x % 1.0 == 0 else x

#Reference layer and update to Unique Value renderer using layer file
mxd = arcpy.mapping.MapDocument("current")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
lyr100 = arcpy.mapping.ListLayers(mxd, "interval_100")[0]
lyrFile = arcpy.mapping.Layer(r"C:\Active\ArcPY\Users\SteveLynch\interval_100.lyr")
arcpy.mapping.UpdateLayer(df,lyr100,lyrFile)

#Apply source data to layer
sym = lyr100.symbology
sym.addAllValues()

#Generate unique list of lables
classList = []
labelList = []

with arcpy.da.SearchCursor(lyr100, ("mean_cont", "low_cont", "high_cont"), sql_clause=(None,"ORDER BY mean_cont")) as rows:
&amp;nbsp; for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; lowCont = str(int_if_you_can(row[1]))
&amp;nbsp;&amp;nbsp;&amp;nbsp; highCont = str(int_if_you_can(row[2]))
&amp;nbsp;&amp;nbsp;&amp;nbsp; if not lowCont + " - " + highCont in labelList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; classValue = in_if_you_can(row[0])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; classList.append(classValue)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; label = lowCont + " - " + highCont
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; labelList.append(label)

#Update layer with new label classes
sym.classValues = classList
sym.classLabels = labelList
arcpy.RefreshActiveView()
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Jeff&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:24:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-uniquevaluessymbology-class-at-10-1/m-p/159241#M12204</guid>
      <dc:creator>jiangjian</dc:creator>
      <dc:date>2021-12-11T08:24:32Z</dc:date>
    </item>
    <item>
      <title>Re: Using UniqueValuesSymbology Class at 10.1</title>
      <link>https://community.esri.com/t5/python-questions/using-uniquevaluessymbology-class-at-10-1/m-p/159242#M12205</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This is double posted.&amp;nbsp; A response can be found at:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums.arcgis.com/threads/90311-Has-anyone-modified-UniqueValuesSymbology�??s-Lyr.symbology.classLabels-successfull?p=320348&amp;amp;posted=1#post320348"&gt;http://forums.arcgis.com/threads/90311-Has-anyone-modified-UniqueValuesSymbology�??s-Lyr.symbology.classLabels-successfull?p=320348&amp;amp;posted=1#post320348&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Aug 2013 13:35:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-uniquevaluessymbology-class-at-10-1/m-p/159242#M12205</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2013-08-12T13:35:50Z</dc:date>
    </item>
  </channel>
</rss>

