# How to choose a field and Apply a General Symbology in Python

I did a very simple field to apply a symbology layer:

import arcpy

mxd = arcpy.mapping.MapDocument('CURRENT')
df = arcpy.mapping.ListDataFrames(mxd, "")[0]
in_layer = arcpy.mapping.ListLayers(mxd, "", df)[0]
in_symbology_layer = arcpy.mapping.Layer(r"F:\PercACH.lyr")

arcpy.ApplySymbologyFromLayer_management(in_layer,in_symbology_layer)


This *.lyr works well, but only in one field (year 2003). I want to do the process below:

Choose a feature class in GDB -> Choose the Field -> Apply a Symbology -> Generate a layout and export in PDF or PNG.

The export process I already did, but not with the field chosen step.

EDIT: all the fields has the same range.

Be sure to set the workspace and env. then export to whatever format you want and your desired location.

#Apply Symbology to newly created layers
lyr1 = r"Y:\Path\to\layer\file" #Layer to apply symbology to

symbolLyr1 = r"Y:\Division Work Folders\path\to\Layer\file" #Layer file with desired symbology
arcpy.ApplySymbologyFromLayer_management(lyr1, symbolLyr1) #Apply symbology to Liquor Stores

mxd.save()

• Joe, I already did this step. I have some doubts in how to choose a field and apply a general .lyr file to my active layer. – Vinicius Cruvinel Jul 7 '17 at 16:00
• you don't. your layer file already has properties set to it for its symbology to be impacted by the field chosen. you simply apply that symbology layer to your desired shapefile/FC. I use this in many of my .py scripts and it works what doubts are you having exactly? Are you seeing any error? – NULL.Dude Jul 7 '17 at 16:02
• Joe, sorry, I understand now. But I want to put a parameter (field), choose the field and apply the layer direct in the choosen one. – Vinicius Cruvinel Jul 7 '17 at 16:04
• Ah, I see what you mean. you want the symbology to reflect a different field for different results and then export those results? Not sure in Arcpy but you can create a new .lyr file for each field and use those .lyr files in a loop. – NULL.Dude Jul 7 '17 at 16:08
• I will do some code and put here to discuss – Vinicius Cruvinel Jul 7 '17 at 16:09

Problem solved. Just need to use:

lyr.symbology.valueField = "ACH_M1S_2003"


This line helps to choose a field, just set a parameter if the user wnats to change the fields.

Field1 = arcpy.GetParameterAsText(0)


and after, put this line in the if conditions.

lyr.symbology.valueField = "Field1"


Using a parameter can put many more conditions to the script.

mxd = arcpy.mapping.MapDocument('CURRENT')
df = arcpy.mapping.ListDataFrames(mxd, "")[0]
lyr = arcpy.mapping.ListLayers(mxd, "", df)[0]
lyrFile = arcpy.mapping.Layer(r"F:\PercACH.lyr")
arcpy.mapping.UpdateLayer(df, lyr, lyrFile, True)