<?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: Error setting field for UniqueValueRenderer in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/error-setting-field-for-uniquevaluerenderer/m-p/1288555#M67632</link>
    <description>&lt;P&gt;There is one post on SO that mentions that the layers datasource was broken and he was getting this error.&amp;nbsp; I'm sure you worked that out already so maybe it would be helpful to report this to esri? No too long ago there was another question on here about changing values and the method to do so in the docs were not working so maybe there is something really wrong with the UniqueValueRenderer class.&lt;/P&gt;</description>
    <pubDate>Fri, 12 May 2023 13:02:10 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2023-05-12T13:02:10Z</dc:date>
    <item>
      <title>Error setting field for UniqueValueRenderer</title>
      <link>https://community.esri.com/t5/python-questions/error-setting-field-for-uniquevaluerenderer/m-p/1287218#M67606</link>
      <description>&lt;P&gt;Hi.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to change the symbology of one of my layers in a python script. I've found the given layer&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Get layer "Vegteig" from active map
aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.activeMap
fl_vegteig = m.listLayers("Vegteiger")[0]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I'm trying to define a new UniqueValueRenderer for the layer:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;symb = fl_vegteig.symbology
symb.updateRenderer("UniqueValueRenderer")
symb.renderer.fields = ['TILKNYTTET']&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;When I try to run this, I get this error:&lt;/P&gt;&lt;PRE&gt;The attribute 'fields' is not supported on this instance of UniqueValueRenderer&lt;/PRE&gt;&lt;P&gt;Does anyone know what might be wrong? I'm using almost the same code in another script (same toolbox), which works perfectly.&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 13:20:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-setting-field-for-uniquevaluerenderer/m-p/1287218#M67606</guid>
      <dc:creator>TorbjørnDalløkken2</dc:creator>
      <dc:date>2023-05-09T13:20:34Z</dc:date>
    </item>
    <item>
      <title>Re: Error setting field for UniqueValueRenderer</title>
      <link>https://community.esri.com/t5/python-questions/error-setting-field-for-uniquevaluerenderer/m-p/1288555#M67632</link>
      <description>&lt;P&gt;There is one post on SO that mentions that the layers datasource was broken and he was getting this error.&amp;nbsp; I'm sure you worked that out already so maybe it would be helpful to report this to esri? No too long ago there was another question on here about changing values and the method to do so in the docs were not working so maybe there is something really wrong with the UniqueValueRenderer class.&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2023 13:02:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-setting-field-for-uniquevaluerenderer/m-p/1288555#M67632</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2023-05-12T13:02:10Z</dc:date>
    </item>
    <item>
      <title>Re: Error setting field for UniqueValueRenderer</title>
      <link>https://community.esri.com/t5/python-questions/error-setting-field-for-uniquevaluerenderer/m-p/1325678#M68538</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Did you find a solution to this? I'm developing some code in Arcpro 3.1.3 and I too get the same vague error. I've tried running it in the python command line window as well as notebook. I've also saved the project, re-opened it with the layer in it and tried running the code below. The layer exists, so its not a broken layer,there is sensible data in it and SubNetID field exists. If I go to the Symbology panel in ArcPro and set it to unique value, subnetid, then it all uniquely colours so I know the dataset is OK. Dare I say it that ESRI have somehow broken this with an update?&lt;/P&gt;&lt;P&gt;My code is simply:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject("Current")
aprxMap = aprx.listMaps("Map")[0]
layer = aprxMap.listLayers('Sub1000_3')[0]  # This layer was initially loaded into the map as a single symbol
aSymbology = layer.symbology
aSymbology.updateRenderer('UniqueValueRenderer')
aSymbology.renderer.fields = ["SubNetID"]
p = arcpy.mp.ArcGISProject("CURRENT")
cr = p.listColorRamps("Basic Random")[0]
aSymbology.colorRamp = cr
layer.symbology = aSymbology&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It fails on line 6 with&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;NameError&lt;/SPAN&gt;: The attribute 'fields' is not supported on this instance of UniqueValueRenderer.&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Trying to think out of the box, you could argue the renderer has not been given any values to render but it seems to be a chicken and egg situation, how can I give it values when the &lt;STRONG&gt;first&lt;/STRONG&gt; step is to say which field you want to render on, but its that line it fails on!&lt;/P&gt;&lt;P&gt;I've tagged a few of python gurus into this to see if they can identify the issue:&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1066"&gt;@DanPatterson_Retired&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1325"&gt;@curtvprice&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1108"&gt;@XanderBakker&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1371"&gt;@JoshuaBixby&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 00:02:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-setting-field-for-uniquevaluerenderer/m-p/1325678#M68538</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2023-09-06T00:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: Error setting field for UniqueValueRenderer</title>
      <link>https://community.esri.com/t5/python-questions/error-setting-field-for-uniquevaluerenderer/m-p/1327004#M68558</link>
      <description>&lt;P&gt;The &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/uniquevaluerenderer-class.htm#C_GUID-0A517828-8472-4FBF-88A3-1E3C75988432" target="_self"&gt;first code sample in the help&lt;/A&gt; does it exactly the way you're doing it, so I'm kind of mystified too.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Sep 2023 20:56:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-setting-field-for-uniquevaluerenderer/m-p/1327004#M68558</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2023-09-08T20:56:30Z</dc:date>
    </item>
    <item>
      <title>Re: Error setting field for UniqueValueRenderer</title>
      <link>https://community.esri.com/t5/python-questions/error-setting-field-for-uniquevaluerenderer/m-p/1327404#M68583</link>
      <description>&lt;P&gt;I've been exploring this problem and it appears to be an issue with the number of unique values. I need to symbolise 13,000 values and this could easily be more.&amp;nbsp; The GUI handles it but when I set it to be an&amp;nbsp;UniqueValueRenderer in arcpy it blows up with a misleading error message. The property sampleSize does not appear when accessing the renderer properties (that sees like a cosmetic bug to me) as I can set it, but it has no affect.&lt;/P&gt;&lt;P&gt;I wondered about going down the CIM route but&amp;nbsp; because the object model is not clear and there appears to be zero examples anywhere on the internet of setting the symbology of a layer to be unique values using CIM in arcpy it is impossible for me to test my code as EVERYTIME I try something ArcPro crashes throwing me out into Windows...&lt;/P&gt;&lt;P&gt;It would be good if esri released some code samples of using CIM to create an&amp;nbsp;UniqueValueRenderer in arcpy. All I have seen on the internet are c# solutions.&lt;/P&gt;&lt;P&gt;Quite frustrating.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Sep 2023 18:47:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-setting-field-for-uniquevaluerenderer/m-p/1327404#M68583</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2023-09-11T18:47:12Z</dc:date>
    </item>
    <item>
      <title>Re: Error setting field for UniqueValueRenderer</title>
      <link>https://community.esri.com/t5/python-questions/error-setting-field-for-uniquevaluerenderer/m-p/1370151#M69651</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/3515"&gt;@DuncanHornby&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1325"&gt;@curtvprice&lt;/a&gt;&amp;nbsp;Did you guys find any solutions? I can't figure this out. I have a couple of python scripts which after some updates sets a uniquevaluerenderer as described in the first post. In one of the scripts (using the same layer) it works, and in the other script it fails. Unfortunatly this error seems to be happening in ArcGIS Pro 3.2 as well.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2024 13:23:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-setting-field-for-uniquevaluerenderer/m-p/1370151#M69651</guid>
      <dc:creator>TorbjørnDalløkken2</dc:creator>
      <dc:date>2024-01-15T13:23:06Z</dc:date>
    </item>
    <item>
      <title>Re: Error setting field for UniqueValueRenderer</title>
      <link>https://community.esri.com/t5/python-questions/error-setting-field-for-uniquevaluerenderer/m-p/1370156#M69652</link>
      <description>&lt;P&gt;No, I came to the conclusion its some sort of bug based upon number of unique values, so my code just traps the error and fails gracefully.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2024 14:07:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-setting-field-for-uniquevaluerenderer/m-p/1370156#M69652</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2024-01-15T14:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: Error setting field for UniqueValueRenderer</title>
      <link>https://community.esri.com/t5/python-questions/error-setting-field-for-uniquevaluerenderer/m-p/1509620#M71119</link>
      <description>&lt;P&gt;Recently, I had to change the layer symbology using CIM. I didn't use UniqueValues, but I hope this helps.&lt;/P&gt;&lt;P&gt;Note: The value of "val['renderer']" was obtained from the .lyrx file (to get the symbology settings, I had to change the file extension to '.json').&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    for item, val in dict_feat.items():
            layer = mapFrame.map.addDataFromPath(val['shape'])
            layer.name = item
            cim_lyr = layer.getDefinition('V2')
            cim_lyr.renderer = val['renderer']
            layer.setDefinition(cim_lyr)&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 24 Jul 2024 21:09:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-setting-field-for-uniquevaluerenderer/m-p/1509620#M71119</guid>
      <dc:creator>makitahideki</dc:creator>
      <dc:date>2024-07-24T21:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: Error setting field for UniqueValueRenderer</title>
      <link>https://community.esri.com/t5/python-questions/error-setting-field-for-uniquevaluerenderer/m-p/1607877#M74070</link>
      <description>&lt;P&gt;Adding on to note that I have experienced this kind of bug when attempting to set a field on a layer with 0 features. Seems to error out on both extremes (too many records, or too few).&lt;/P&gt;</description>
      <pubDate>Mon, 21 Apr 2025 22:13:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-setting-field-for-uniquevaluerenderer/m-p/1607877#M74070</guid>
      <dc:creator>mattkramer</dc:creator>
      <dc:date>2025-04-21T22:13:08Z</dc:date>
    </item>
    <item>
      <title>Re: Error setting field for UniqueValueRenderer</title>
      <link>https://community.esri.com/t5/python-questions/error-setting-field-for-uniquevaluerenderer/m-p/1618377#M74283</link>
      <description>&lt;P&gt;Just a note that I have a &lt;A href="https://community.esri.com/t5/python-questions/working-example-apply-uniquevaluerenderer-with/m-p/1618515#M74286" target="_self"&gt;working script&lt;/A&gt; as part of a broader implementation:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Feature class is of type Point (e.g. Centroid of countries)&lt;/LI&gt;&lt;LI&gt;Field name must be the internal field name (e.g. Country_Flag), not alias name (e.g. Country Flag). It is also case sensitive&lt;/LI&gt;&lt;LI&gt;Country_Flag field contains 238 unique values&lt;/LI&gt;&lt;LI&gt;Step 1: set default renderer with default 'Shape Marker' symbol, based on Country_Flag field values&lt;/LI&gt;&lt;LI&gt;Step 2: modify each symbol with their corresponding 'Picture Marker', based on images of country flags stored in a folder on disk. Each image's filename corresponds to exactly a value name in the Country_Flag field&lt;/LI&gt;&lt;/UL&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;LI-CODE lang="python"&gt;    def set_defaultuniquevaluesrenderer(featurelayer=None, fieldname=None):
        """Set a default unique values renderer for the specified field in the feature layer."""
        if featurelayer is None:
            arcpy.AddError("Layer not found. Symbology not updated.")
        
        sym = featurelayer.symbology
        sym.updateRenderer('UniqueValueRenderer')
        sym.renderer.fields = [fieldname]
        featurelayer.symbology = sym
        arcpy.AddMessage(f"Symbology updated to UniqueValueRenderer on field: {fieldname}")

    def set_updatesymbology(featurelayer=None, fieldname=None, imagefolder=None):
        """Update only the point symbols as picture markers with corresponding images."""
        if featurelayer is None:
            arcpy.AddError("Layer not found. Symbology not updated.")

        # Get the CIM (Cartographic Information Model) definition of the layer
        cim = featurelayer.getDefinition('V3')
        renderer = cim.renderer

        # Iterate through each class in the renderer's first group
        for classDef in renderer.groups[0].classes:
            # Get the value for the symbol (usually the flag image filename)
            try:
                value = classDef.values[0].fieldValues[0]
            except (AttributeError, IndexError, TypeError):
                arcpy.AddWarning(f"Skipping class with no valid value for symbol: {classDef.name}")
                continue
            
            # Build the full path to the image file
            imagePath = os.path.join(imagefolder, value)
            if arcpy.Exists(imagePath):
                # Read and encode the image as base64
                with open(imagePath, "rb") as imgFile:
                    encoded = base64.b64encode(imgFile.read()).decode("utf-8")
                # Define a CIMPictureMarker using the encoded image
                pictureMarker = {
                    "type": "CIMPictureMarker",
                    "enable": True,
                    "size": 10,
                    "url": f"data&amp;amp;colon;image/png;base64,{encoded}",
                }
                # Create a CIMPointSymbol with the picture marker
                pointSymbol = {
                    "type": "CIMPointSymbol",
                    "symbolLayers": [pictureMarker]
                }
                # Create a CIMSymbolReference for the class symbol
                symbolRef = {
                    "type": "CIMSymbolReference",
                    "symbol": pointSymbol
                }
                # Assign the new symbol to the class definition
                classDef.symbol = symbolRef

        # Apply the updated CIM definition back to the feature layer
        featurelayer.setDefinition(cim)
        arcpy.AddMessage("Point symbols updated with corresponding flag images.")&lt;/LI-CODE&gt;&lt;P&gt;&lt;div class="lia-vid-container video-embed-center"&gt;&lt;div id="lia-vid-6373528372112w996h540r712" class="lia-video-brightcove-player-container"&gt;&lt;video-js data-video-id="6373528372112" data-account="6161463677001" data-player="default" data-embed="default" class="vjs-fluid" controls="" data-application-id="" style="width: 100%; height: 100%;"&gt;&lt;/video-js&gt;&lt;/div&gt;&lt;script src="https://players.brightcove.net/6161463677001/default_default/index.min.js"&gt;&lt;/script&gt;&lt;script&gt;(function() {  var wrapper = document.getElementById('lia-vid-6373528372112w996h540r712');  var videoEl = wrapper ? wrapper.querySelector('video-js') : null;  if (videoEl) {     if (window.videojs) {       window.videojs(videoEl).ready(function() {         this.on('loadedmetadata', function() {           this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) {             bar.setAttribute('role', 'presentation');             bar.setAttribute('aria-hidden', 'true');           });         });       });     }  }})();&lt;/script&gt;&lt;a class="video-embed-link" href="https://community.esri.com/t5/video/gallerypage/video-id/6373528372112"&gt;(view in My Videos)&lt;/a&gt;&lt;/div&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 May 2025 13:52:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-setting-field-for-uniquevaluerenderer/m-p/1618377#M74283</guid>
      <dc:creator>Samy_BoumaNgock</dc:creator>
      <dc:date>2025-05-27T13:52:46Z</dc:date>
    </item>
    <item>
      <title>Re: Error setting field for UniqueValueRenderer</title>
      <link>https://community.esri.com/t5/python-questions/error-setting-field-for-uniquevaluerenderer/m-p/1659282#M74787</link>
      <description>&lt;P&gt;Just came across this and have found it super useful. I have successfully used the script to load images as symbols for around 400 unique class values. What I have searched for and not found, is how to set the Quality attribute to "Picture" rather than the "Draft" that it defaults to.&lt;/P&gt;&lt;P&gt;I added in another line between where the Size and the URL are set as per below:&lt;/P&gt;&lt;P&gt;"quality": 'Picture',&lt;/P&gt;&lt;P&gt;&amp;nbsp;I also tried 'Picture Quality' and neither option had any affect.&lt;/P&gt;&lt;P&gt;There are too many to go and set this manually for 400 unique values. Any ideas?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Oct 2025 12:37:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-setting-field-for-uniquevaluerenderer/m-p/1659282#M74787</guid>
      <dc:creator>AlanTonkinFMC</dc:creator>
      <dc:date>2025-10-21T12:37:53Z</dc:date>
    </item>
  </channel>
</rss>

