¿Can I change symbology of layer from "OTHER" to "UNIQUE_VALUES" ?

2096
3
03-18-2016 02:37 PM
AuraRamos_Lora1
New Contributor II

When I add a layer this by default  is "OTHER", I want to apply unique value by default  programmatically by some field.

import arcpy
dirmxd = "D:\Borrrar\D143\Ejecutables\D143v10_3.mxd"
fc = "D:\Borrrar\D143\BaseMapas.gdb\estruclin"
mxd=arcpy.mapping.MapDocument(mxd)
df = arcpy.mapping.ListDataFrames(mxd)[0]
layer = arcpy.MakeFeatureLayer_management(fc,"estruc")
lyr = arcpy.mapping.Layer(layer)
arcpy.mapping.AddLayer(df, lyr, "AUTO_ARRANGE")
tipo = lyr.symbologyType ### print OTHER

I don´t have a lyr, I have a general style  that I want to apply with class styleItem: legend.updateItem(lyr, styleItem)

I seen a example: http://desktop.arcgis.com/es/desktop/latest/analyze/arcpy-mapping/styleitem-class.htm

but first I need a layer classify by unique value.

Perhaps I have to generate the classified layer before add, but I don't know how to do it without ever having another layer of reference.

  Thanks and regards...



0 Kudos
3 Replies
DanPatterson_Retired
MVP Emeritus

Aura ... have you explored some of the appropriate portions of the arcpy classes and methods? for example

UniqueValuesSymbology—Help | ArcGIS for Desktop

0 Kudos
AuraRamos_Lora1
New Contributor II

UniqueValuesSymbology—Help | ArcGIS for Desktop

import arcpy
mxd = arcpy.mapping.MapDocument("current")
lyr = arcpy.mapping.ListLayers(mxd, "Population")[0]
if lyr.symbologyType == "UNIQUE_VALUES":
  lyr.symbology.valueField = "SUB_REGION"
  lyr.symbology.addAllValues()
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
del mxd

Of course I've seen the class , this can only be used if the layer previously is defined with "UNIQUE_VALUES ". But as I explained earlier when I add the default layer symbology is OTHERS, I would like to generate a unique symbology when I make the layer . ¿Could you help me with an example?

0 Kudos
DanPatterson_Retired
MVP Emeritus

I only see UpdateLayer—Help | ArcGIS for Desktop which implies you have to have something already prepared to use.  I can't find anything offhand to actually create the classification within arcpy mapping or arcpy ma (in PRO), but I don't do much mapping automation, so I will have to defer to those that do.

0 Kudos