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!
Solved! Go to Solution.
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().
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.
There is also: Apply Symbology From Layer
That isn't just for arcpy within ArcGIS Pro, assuming that's different somehow? I'm using ArcMap.
For Desktop 10.3-10.6 versions: Apply Symbology From Layer
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.
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().