Skip to main content
3 of 3
edited tags
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

Applying symbology to layers within the Table of Contents with Python

I am using arcpy to pull in layers from a file geodatabase but I receive the following error below. How can I assign symbology from a .lyr file to a TOC layer using arcpy?

# Name: Create Map
# Purpose: Fixes bugs and other mapping problems 

# Import system modules
import arcpy
from arcpy import env

# Set the current workspace
env.workspace = "I:\UPDM.gdb"

# Rebuild Map Workspace
#
mxd = arcpy.mapping.MapDocument(r"C:\Users\aa2zz6\Desktop\test\Untitled.mxd")

df = arcpy.mapping.ListDataFrames(mxd, "*")[0]
# Add layer to TOC
#
addLayer = arcpy.mapping.Layer(r"I:\UPDM.gdb\P_PipeSystem\P_Meters")
arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")

#Set layer to apply symbology to
inputLayers = ["P_Meters",]

# Set layer that output symbology will be based on
symbologyLayer = (r"C:\Temp\Meters.lyr")

# Apply the symbology from the symbology layer to the input layer
for layer in inputLayers:
arcpy.ApplySymbologyFromLayer_management (layer, symbologyLayer)

Error

Traceback (most recent call last):
File "C:\Users\aa2zz6\Downloads\CREATE NEW MXD.py", line 29, in <module>
arcpy.ApplySymbologyFromLayer_management (layer, symbologyLayer)
File "C:\Program Files (x86)\ArcGIS\Desktop10.6\ArcPy\arcpy\management.py", 
line 6934, in ApplySymbologyFromLayer
raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Layer: Dataset P_Meters does not exist or is not 
supported
Failed to execute (ApplySymbologyFromLayer).
aa2zz6
  • 115
  • 7