How do I properly use UpdateLayer to change symbology for layer?

198
6
Jump to solution
02-08-2019 02:48 PM
Kevin_C
New Contributor III

I am trying to change the symbology of a layer in a map document using arcpy. I have a reference layer I am using. Please see the following code:

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
nuristanGeol = arcpy.mapping.Layer(r"C:\GeolAfghanProvince.gdb\Nuristan_geology")
afgGeol = arcpy.mapping.Layer(r"C:\afgeolmap.lyr")
arcpy.mapping.UpdateLayer(df, nuristanGeol, afgGeol)

This doesn't return anything or update the layers with new symbology. I also tried refreshing the view and TOC. 

What am I doing wrong here? 

Thanks!

0 Kudos
1 Solution

Accepted Solutions
Kevin_C
New Contributor III

The issue was me trying to use arcpy.mapping.Layer() to define the nuristanGeol feature class which is the layer to be updated. I should've used arcpy.mapping.ListLayers(mxd) to point a variable at nuristanGeol. And then call this variable within UpdateLayer().

View solution in original post

0 Kudos
6 Replies
JoshuaBixby
MVP Esteemed Contributor

This doesn't return anything

Regarding the code not returning anything, you need to AddLayer—Help | ArcGIS Desktop after you create it.  That may address your second issue to, but I don't have time to test.

0 Kudos
RandyBurton
MVP Regular Contributor
Kevin_C
New Contributor III

That isn't just for arcpy within ArcGIS Pro, assuming that's different somehow? I'm using ArcMap. 

0 Kudos
RandyBurton
MVP Regular Contributor

For Desktop 10.3-10.6 versions: Apply Symbology From Layer

Kevin_C
New Contributor III

Thanks, I'll try that out when I get back to work. Although I'm still trying to figure out how I screwed up UpdateLayer.

0 Kudos
Kevin_C
New Contributor III

The issue was me trying to use arcpy.mapping.Layer() to define the nuristanGeol feature class which is the layer to be updated. I should've used arcpy.mapping.ListLayers(mxd) to point a variable at nuristanGeol. And then call this variable within UpdateLayer().

View solution in original post

0 Kudos