Hi there
I would like to learn how to modify/add categories within Symbology programmatically in arcpy.
I have created a Featurelayer from a shapefile. Now I want to set the available categories
Is this possible and if so what is the code necessary to perform this function.
Cheers
Peter
see arcpy.mapping ... for example
EDIT the direct links didn't work so I will give references to the actual classes
in the arcpy mapping classes section Introduction to arcpy.mapping—Help | ArcGIS for Desktop
UniqueValuesSymbology
GraduatedColorsSymbology
GraduatedSymbolsSymbology
The code samples will get you started
Hi Dan
Seems that I can't get the links to work but you've given me the functions I need to use so that's the important point
Cheers
Peter
Yes Peter, sometimes this happens and I still can't get them to work, but they are in the arcpy.mapping section under Classes
Thanks again
I've tried the snippet of code however, I think I need to understand a bit more about symbologyType and where it captures this attribute from within an mxd.
would you mind if I provided you the mxd as it's created from BOM shapefiles which produces the layers.
When I run the code SymbologyType comes back as 'OTHER'
I'm obviously missing something.
print lyr.symbologyType
Returns 'OTHER'
if lyr.symbologyType == "UNIQUE_VALUES":
lyr.symbology.valueField = "SUB_REGION"
lyr.symbology.addAllValues()
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
Cheers
Peter
well OTHER means .... A string that represents an unsupported layer symbology class.
So what is your symbology class, there is only the list in the layer class
What is the layer? a featureclass?
You are running it from the current project as follows
import arcpy
mxd = arcpy.mapping.MapDocument("current") # run from within a currently open project
lyr = arcpy.mapping.ListLayers(mxd, "Population")[0] # this is a layer(s) called Population within the project [0] means get the 1st
if lyr.symbologyType == "UNIQUE_VALUES": # it then checks to see if this is the symbology type
lyr.symbology.valueField = "SUB_REGION" # if it is, use a specific field in the layer's table
etc etc etc