problem with ApplySymbologyFromLayer_management not applying symbology

5030
3
02-27-2013 10:55 AM
karlkliparchuk1
New Contributor
I am running ArcGIS v10.1. Here is a snippet of my arcpy code.  I am trying to apply symbology to point features.  The layer to display and my symbology layer both have the attribute "DESCRIPT" to match to.  I can apply the symbology manually in ArcMap, but when I try this code, it does not do it, even with a screen refresh.  Any ideas as to the problem?  The screen capture shows the layer added to the top of the TOC.

Thanks.
Karl
_______________

layerName = "crime_95"
outFeature = "crimejoinKK.shp"
crimeLayer = "crimejoinLayer"
symbologyLayer =  r"C:\temp\CrimeTypes.lyr"
crimeType = "CrimeTypes"


#Process: Copy layer
# Copy the crime layer to a new permanent feature class
arcpy.CopyFeatures_management(layerName, outFeature)


# First, Add Field - need to add a field that will match the field in the symbology layer
arcpy.AddField_management(outFeature, "DESCRIPT", "TEXT")
# Then Calculate Field - calculate the field with the crime descriptions
arcpy.CalculateField_management(outFeature, "DESCRIPT", "[crime95d_9]", "VB", "")
# Make a temporary layer to apply the symbology to
arcpy.MakeFeatureLayer_management(outFeature, crimeLayer)

#BELOW IS WHERE THE PROBLEM IS.
#I am adding crimeLayer to the data frame, then applying symbology to it.
#The point symbols show up, but not the symbology applied to them.

addCrimeLayer = arcpy.mapping.Layer(crimeLayer)
df = arcpy.mapping.ListDataFrames(mxd, "New Data Frame")[0]
arcpy.mapping.AddLayer(df, addCrimeLayer, "TOP")
arcpy.ApplySymbologyFromLayer_management(addCrimeLayer, symbologyLayer)
arcpy.RefreshActiveView()

----------
[ATTACH=CONFIG]22229[/ATTACH]
Tags (2)
0 Kudos
3 Replies
ErikMartin
Occasional Contributor
I've done something very similar.  My code was for 10.0, but it still works in 10.1.  I'm not sure if there's a new, better way to do this, but here's the relevant section of my code:
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
arcpy.MakeFeatureLayer_management("myFC", "My Layer Name")
addLayer = arcpy.mapping.Layer("My Layer Name")
arcpy.mapping.AddLayer(df,addLayer, "TOP")
sourceLayer = "C:\Data\MySymbology.lyr"
layerSymb = arcpy.mapping.Layer(sourceLayer)
updateLayer = arcpy.mapping.ListLayers(mxd, "My Layer Name", df)[0]
arcpy.mapping.UpdateLayer(df, updateLayer, layerSymb, "TRUE")
arcpy.RefreshTOC()


Hope that helps...
-Erik
0 Kudos
MIGUELFERNANDEZ1
New Contributor
Thanks! It works! I was having exactly the same problem I don't know why
0 Kudos
MakikoShukunobe
New Contributor

I had the same problem. I think it is because the "Value Field" is set to "Single symbol" by default.  The code below worked for me.

lyr = "path to your layer"

in_symbol_layer = "path to your symbology layer"

addLayer = arcpy.mappling.Layer(lyr)

addLayer.valueField = "the value field you want to use for the symbol"

arcpy.ApplySymbologyFromLayer_management(lyr, in_symbol_layer)

0 Kudos