AnsweredAssumed Answered

Save feature class as lyrx file - ArcPy (ArcGIS Pro)

Question asked by bisoftware on Sep 13, 2018
Latest reply on Sep 13, 2018 by Dan_Patterson

I have a python script that finds the feature class with the highest count for a field called 'SUM_USER_VisitCount' and then creates the symbology I specify. What I then want to do is save this feature class as a lyrx file, but the code I have for this seems to get skipped over. Can someone help me figure out what I'm doing wrong?

 

Here is a section of my code (let me know if you need to see the whole code):

 ### get key for dictionary item with the highest value
        highest_count_layer = max(results_dict, key=results_dict.get)
        print(highest_count_layer)
        print(results_dict[highest_count_layer])
        #print(results_dict)
               

        for row in searchCursor:
            Symbology_Layer = highest_count_layer
            sym = Symbology_Layer.symbology
           
            if hasattr(sym, 'renderer'):
                if sym.renderer.type == 'SimpleRenderer':
                    sym.updateRenderer('GraduatedColorsRenderer')
                    sym.renderer.classificationField = 'SUM_USER_VisitCount'
                    sym.renderer.breakCount = 5
                    sym.renderer.colorRamp = p5.listColorRamps('Orange-Red (Continuous)')[0]
                    ### Remove decimal places from labels
                    if sym.renderer == "GraduatedColorsRenderer":
                        breaks = sym.renderer.classBreaks
                        for b in breaks:
                            b_int = b.label[0:-7]
                            b.label = b_int
                            ### Thousands Separators in labels
                            def FindLabel (b):
                                return "{:,}".format(float(b))
                   
                   
                   
                    Symbology_Layer.symbology = sym
                   
                    p5.save()
                   
                    ### Where lyrx will be saved
                    arcpy.env.workspace = r"E:\arcGIS_Shared\Python\Symbology Layers"
                   
                    ### Set local variables
                    in_layer = Symbology_Layer
                    out_layer_file = r"E:\arcGIS_Shared\Python\Symbology Layers\SGF_CumulativeSymbology.lyrx"
                   
                    arcpy.management.SaveToLayerFile(in_layer, out_layer_file, "ABSOLUTE")
                   
                    print('Lyrx file saved')

Outcomes