Select to view content in your preferred language

Question regarding Symbology Renderers and .listMissingValues()

749
4
Jump to solution
08-25-2022 10:46 AM
anonymous_geographer
Frequent Contributor

Hello,

I'm encountering an issue with my Python script (using the standard libraries packaged within Pro 3.0.0 and Pro 3.0.1 installs).

My goal has been to update some symbology within my Pro project. To do this, I locate all values that are not part of our symbology rendering, and simply add them into the existing renderer group. Using the .listMissingValues() functionality, I am able to locate these, add them with .addValues(), and this accomplishes the task successfully. Hooray!  However, the problem lies in scenarios where there are 0 missing values. If the script does not find any missing values, the tool fails and produces this error:

Traceback (most recent call last):
File "C:\My\Python\Path\To\Script.py", line 27, in <module>
list_missing_values = layer_symbology.renderer.listMissingValues()
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_renderer.py", line 41, in listMissingValues
self._arc_object.listMissingValues(*gp_fixargs((), True)))
SystemError: <built-in method listMissingValues of MappingSymbologyObject object at 0x00000172C4BAA9B0> returned NULL without setting an error

Is the .listMissingValues() method not designed to handle scenarios with 0 missing values, or am I missing something obvious? I assumed it would just spit out an empty list if it couldn't find any missing values, but that doesn't seem to be the case. I could band-aid this with a Try/Except to ignore SystemError messages for the .listMissingValues() step, but I would prefer not to do that.

Anyway, thanks for any assistance!


Here is my script thus far (when there are 0 missing values, the error mentioned above occurs at Line 27):

 

 

import arcpy

aprx = arcpy.mp.ArcGISProject("The\\Project\\Path\\Being\\Used.aprx")

for a_map in aprx.listMaps():

    if a_map.name != "Name of Map I am Needing":

        continue

    else:

        print("Map Name: " + a_map.name)

        for a_layer in a_map.listLayers():
            
            if a_layer.name != "Layer Name I am Needing":

                continue

            else:

                print("Layer Name: " + a_layer.name)

                layer_symbology = a_layer.symbology

                list_missing_values = layer_symbology.renderer.listMissingValues()

                if len(layer_symbology.renderer.groups) != 1:

                    print("Group count error, please check symbology groups.")

                else:

                    print("Symbology Group Header: " + str(layer_symbology.renderer.groups[0].heading))

                    if len(list_missing_values) == 0:

                        print("No missing values found.")

                    else:

                        for each_missing_value in list_missing_values:

                            print("Missing value count: " + str(len(each_missing_value.items)))

                            layer_symbology.renderer.addValues({layer_symbology.renderer.groups[0].heading: each_missing_value.items})

                            a_layer.symbology = layer_symbology

                        aprx.save()
                        print("Project saved.")

 

 

 

0 Kudos
1 Solution

Accepted Solutions
anonymous_geographer
Frequent Contributor

After opening a support ticket with Esri, this behavior has been replicated and is being logged as a defect (ENH-000151963). In the meantime, the best workaround would be to deploy the following:

 

try:

    # Attempts to find the missing values and assign to list.
    list_missing_values = layer_symbology.renderer.listMissingValues()

except SystemError:

    # If no missing values, ignore the SystemError generated and assign the list to be empty.
    list_missing_values = []

 

 

View solution in original post

0 Kudos
4 Replies
by Anonymous User
Not applicable

You could try using a conditional to assign the value of the function if it is not Null or 0 if it is null.

EDIT to change the 0 to an empty list.

 

list_missing_values = layer_symbology.renderer.listMissingValues() if layer_symbology.renderer.listMissingValues() is not None else []

 

 

You can take this further and maybe get away with just using the method in the conditional:

if layer_symbology.renderer.listMissingValues():
    for each_missing_value in layer_symbology.renderer.listMissingValues():
        do stuff
else:
    print("Nothing to do")

 

Depending where that error is triggered, try/except may be the way around it.

0 Kudos
anonymous_geographer
Frequent Contributor

Thanks for the idea, Jeff. I just tried it. Unfortunately it's failing with the same error message. It's like Python is getting hung up on the method itself (maybe on the backend somehow...?) and just failing outright. I'll keep digging.

0 Kudos
by Anonymous User
Not applicable

rats, looks like a bug and try/except will probably be your best option until its fixed. 

anonymous_geographer
Frequent Contributor

After opening a support ticket with Esri, this behavior has been replicated and is being logged as a defect (ENH-000151963). In the meantime, the best workaround would be to deploy the following:

 

try:

    # Attempts to find the missing values and assign to list.
    list_missing_values = layer_symbology.renderer.listMissingValues()

except SystemError:

    # If no missing values, ignore the SystemError generated and assign the list to be empty.
    list_missing_values = []

 

 

0 Kudos