1

I have a saved .mxd map in directory called Project.mxd and some layer symbology files .lyrs inside a folder called lyr

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Data\Maps\Project.mxd")
lyrPath = "C:\Data\lyrs\"

How can I map the symbology of Layers inside the map to the layer symbology files .lyr on an stand alone ArcPy Script?

For Example if I have a layer called Population in the Project.mxd how can I apply its symbology from a file called pop-2016.lyr and so on?

enter image description here

I already tried to use this snippet

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Data\Maps\Project.mxd")
lyrPath = "C:\Data\lyrs\"
df = arcpy.mapping.ListDataFrames(mxd, '')[0]
for lyr in arcpy.mapping.ListLayers(mxd, '', df): # Loop through layers
 if lyr.name == "Population":
    arcpy.ApplySymbologyFromLayer_management("Population", "C:\Data\lyrs\pop-2016.lyr")
mxd.save()
del mxd

but I am getting this error

ExecuteError: Failed to execute. Parameters are not valid. ERROR 000732: Input Layer: Dataset Population does not exist or is not supported Failed to execute (ApplySymbologyFromLayer).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.