Skip to main content
edited tags
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345
Post Reopened by Midavalo
Revised Question + added Code & Error
Source Link
aa2zz6
  • 115
  • 7

Apply Symbology Applying symbology to TOC layers using Arcpywithin the Table of Contents with Python

I haveam 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 on my desktop that I would like apply symbology to a TOC sde layer in an existing map document. How can I do this using python IDLEarcpy?

# 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).

Apply Symbology to TOC layers using Arcpy

I have a .lyr file on my desktop that I would like apply symbology to a TOC sde layer in an existing map document. How can I do this using python IDLE?

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).
Post Closed as "Not suitable for this site" by Midavalo
Source Link
aa2zz6
  • 115
  • 7

Apply Symbology to TOC layers using Arcpy

I have a .lyr file on my desktop that I would like apply symbology to a TOC sde layer in an existing map document. How can I do this using python IDLE?