AssertionError from UpdateLayer when symbology_only False

2875
1
Jump to solution
08-29-2012 10:14 AM
StevenHaslemore
Occasional Contributor
Hi,

My scenario is, I have several mxds with the same layers, different layouts, used for map templates. I updated the symbology and labeling details for a layer in one mxd and want to push it into the others.

Attempting the following workflow results in an AssertionError during arcpy.mapping.UpdateLayer()

1. save the new details as a layer file.
2. run this code

files = r'C:\Temp\Layouts'
newLyr = arcpy.mapping.Layer('H:\\GIS_LayerFiles\\WaterNetwork\\Hydrant.lyr')
layerLongName = 'Water Network\\Hydrant'
symbologyOnly = False

for r,d,f in os.walk(files):
    for fl in f:
        path = r+'\\' + fl
        if fl[-3:] =='mxd':
            print path
            mxd = arcpy.mapping.MapDocument(path)
            df = arcpy.mapping.ListDataFrames(mxd)

            layers = arcpy.mapping.ListLayers(mxd)

            for lyr in layers:
                if str(lyr.longName).startswith(layerLongName):
                    arcpy.mapping.UpdateLayer(df,lyr, newLyr, symbologyOnly)
                    print lyr.longName + " symbology updated."



I get the following error

Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\utils.py", line 181, in fn_
return fn(*args, **kw)
File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\mapping.py", line 1477, in UpdateLayer
assert isinstance(data_frame, DataFrame)
AssertionError

Symbology only works fine, but as mentioned I have labeling changes I want to include.

I'd much rather not update them all manually.
0 Kudos
1 Solution

Accepted Solutions
StevenHaslemore
Occasional Contributor
It appears to be a little more particular about the dataframe when it's updating more than just symbology.
The dataframe was passing a list of one dataframe, rather than a dataframe itself, correction below.

files = r'C:\Temp\Layouts'
newLyr = arcpy.mapping.Layer('H:\\GIS_LayerFiles\\WaterNetwork\\Hydrant.lyr')
layerLongName = 'Water Network\\Hydrant'
symbologyOnly = False

for r,d,f in os.walk(files):
    for fl in f:
        path = r+'\\' + fl
        if fl[-3:] =='mxd':
            print path
            mxd = arcpy.mapping.MapDocument(path)
            df = arcpy.mapping.ListDataFrames(mxd)

            layers = arcpy.mapping.ListLayers(mxd)

            for lyr in layers:
                if str(lyr.longName).startswith(layerLongName):
                    arcpy.mapping.UpdateLayer(df[0],lyr, newLyr, symbologyOnly)
                    print lyr.longName + " symbology updated."

View solution in original post

0 Kudos
1 Reply
StevenHaslemore
Occasional Contributor
It appears to be a little more particular about the dataframe when it's updating more than just symbology.
The dataframe was passing a list of one dataframe, rather than a dataframe itself, correction below.

files = r'C:\Temp\Layouts'
newLyr = arcpy.mapping.Layer('H:\\GIS_LayerFiles\\WaterNetwork\\Hydrant.lyr')
layerLongName = 'Water Network\\Hydrant'
symbologyOnly = False

for r,d,f in os.walk(files):
    for fl in f:
        path = r+'\\' + fl
        if fl[-3:] =='mxd':
            print path
            mxd = arcpy.mapping.MapDocument(path)
            df = arcpy.mapping.ListDataFrames(mxd)

            layers = arcpy.mapping.ListLayers(mxd)

            for lyr in layers:
                if str(lyr.longName).startswith(layerLongName):
                    arcpy.mapping.UpdateLayer(df[0],lyr, newLyr, symbologyOnly)
                    print lyr.longName + " symbology updated."

0 Kudos