1

I have several mxds (located in C:\Project ) that have 250 layers each. All the layers as the same name- "plan" and they all in group layers like that (added picture for example): enter image description here

I try to change all symbology layers of "plan" to the same symbology of layer "landuse":

enter image description here

All "plan" layers located one folder that divided to a lot of sub folders and sub-sub folders and their names (in the folders) are "kavim_kchulim". i try this code:

import arcpy,os,sys,string
import arcpy.mapping
from arcpy import env

env.workspace = r"C:\Project"
symbologyLayer = r"C:\Project\layers\landuse.lyr"
for mxdname in arcpy.ListFiles("*.mxd"):
    print mxdname 
    mxd = arcpy.mapping.MapDocument(r"C:\Project\\" + mxdname)
    dfList = arcpy.mapping.ListDataFrames(mxd, "*")
    for df in dfList:
        print df.name 
        for lyr in arcpy.mapping.ListLayers(mxd, "", df):
            if lyr.name == "plan":
                arcpy.ApplySymbologyFromLayer_management("plan", symbologyLayer)
                print 'changed'     
    mxd.save()
del mxd

but get an error:

>>> 
Project.mxd
Layers

Traceback (most recent call last):
  File "C:\Users\yaron.KAYAMOT\Desktop\python.py", line 16, in <module>
    arcpy.ApplySymbologyFromLayer_management("plan", symbologyLayer)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\management.py", line 6470, in ApplySymbologyFromLayer
raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Layer: Dataset plan does not exist or is not supported
Failed to execute (ApplySymbologyFromLayer).

2
  • You have included some print statements in your code which are presumably there to try and help you debug this. It would be equally useful for us to see their output and give context to the error message that you provided.
    – PolyGeo
    Commented Feb 12, 2015 at 10:07
  • now i added the full error
    – newGIS
    Commented Feb 12, 2015 at 10:31

1 Answer 1

3

You should refer to the layer (lyr), not to "plan" when applying the symbology:

arcpy.ApplySymbologyFromLayer_management(lyr, symbologyLayer)

"plan" is just a string so arcpy tries to locate it in your predefined workspace.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.