UniqueValueRenderer method removeValues and addValues does not work correctly if the heading is a blank string

506
3
Jump to solution
10-03-2022 09:09 AM
ccowin_odfw
Occasional Contributor

Hello,

Not sure if I'm doing this wrong but to me this seems like this should work just fine but I get the following error:

 

SystemError: <built-in method addValues of MappingSymbologyObject object at 0x00000151F8882670> returned NULL without setting an error

 

 

The code is as follows:

 

p = arcpy.mp.ArcGISProject(path-to-aprx)
mapList = p.listMaps()

for m in mapList:
    layerList = m.listLayers()

    for layer in layerList:
        sym = layer.symbology

        if hasattr(sym, 'renderer'):
            if sym.renderer.type == 'UniqueValueRenderer':
                groupName = sym.renderer.groups[0].heading

                sym.renderer.removeValues({groupName: ['Spring2022']})
                layer.symbology = sym

                sym.renderer.addValues({groupName: ['Fall2022']})
                layer.symbology = sym

 

 

When I go manually into the aprx and change the headings to not a blank string it works fine.

0 Kudos
1 Solution

Accepted Solutions
RogerDunnGIS
Occasional Contributor II

Great!  Please mark my response as a solution as a kind gesture for my time.  And good luck with all your GIS efforts to make a great web map!!

View solution in original post

0 Kudos
3 Replies
RogerDunnGIS
Occasional Contributor II

I have two suggestions, and I don't which, if either, will work.

  1. Try setting the heading to a space character instead of the empty string.  Perhaps it will be truncated.
  2. Try setting the heading to some value, perform your operations, and then set it to the empty string (or space, as above)

Let us know and good luck!

0 Kudos
ccowin_odfw
Occasional Contributor

Thanks for the reply Roger, I just tested it out and it does work with only a space and it does truncate itself, thanks for the suggestion! I had just changed the heading manually and continued with the project, but this makes the legend in the ultimate web map much cleaner because it just puts the icon in line with the field value.

0 Kudos
RogerDunnGIS
Occasional Contributor II

Great!  Please mark my response as a solution as a kind gesture for my time.  And good luck with all your GIS efforts to make a great web map!!

0 Kudos