BrokenLegMike

Python: Set Definition Query and addAllValues Using UniqueValuesSymbology Class

Discussion created by BrokenLegMike on Aug 23, 2012
Latest reply on Aug 24, 2012 by BrokenLegMike
I'm trying to set a definition query on a layer in a map using python. I want to further use the UniqueValuesSymbology class to addAllValues.

When I do this manually, (i.e. set a definition query and then add all values in the symbology tab on the layer) the values that get added are limited to what's in the definition query, which is what I want. I wrote a script and it sets the definition query as I'd like it, but it doesn't seem to add all the values to the symbology properties dialogue box afterwards.

In my script, I've tried to set the definition query first, refresh the activeview and TOC (I'm assuming this virtually clicks the "Apply" button in the layers properties dialogue box) and then I addAllValues and refresh again. The values aren't getting added. My original Unique Values list remains. Can anyone see what the problem might be?

Thanks,
Mike


   #Set mxd
#Set dataframe
#Loop layers
sList = []
if lyr.name == "Legend":
        arcpy.SelectLayerByLocation_management(lyr, "INTERSECT", "Boundary")
        for row in arcpy.SearchCursor(lyr):
               soilList.append("'{}'".format(row.SMU))
        lyr.definitionQuery = '"SMU" in ({})'.format(", ".join(set(sList)))
        arcpy.RefreshActiveView()
        arcpy.RefreshTOC()                            

        if lyr.symbologyType == "UNIQUE VALUES":
               lyr.symbology.valueField = "SMU"
               lyr.symbology.addAllValues()
        arcpy.RefreshActiveView()
        arcpy.RefreshTOC()                              
        arcpy.SelectLayerByLocation_management(lyr, "CLEAR_SELECTION")

Outcomes