Select to view content in your preferred language

UpdateLayer Assertion Error

2827
1
07-02-2012 08:27 AM
AllenSmith
Deactivated User
Greetings.

I am writing some code to clip a soils layer based on a selected boundray polygon and want the clipped soils layer "SoilsClip" to have the same symbology and label properties as the source layer "Soils".  i am using the UpdateLayer command and keep getting an Assertion Error.  Please provide any help you can.  Thanks.
#Import modules
import os
import sys
import arcpy

#Set Map Document
mxd = arcpy.mapping.MapDocument("Current")

#Set Overwrite Option
arcpy.env.overwriteOutput = True

#Create Map Layer
arcpy.MakeFeatureLayer_management("Boundary", "Boundary_Selection.lyr")

#Add Boundary Selection Layer to Layers Data Frame
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
addLayer = arcpy.mapping.Layer("Boundary_Selection.lyr")
arcpy.mapping.AddLayer(df, addLayer)

#Set Boundary Selection symbology
SymbologyLayer = ("Boundary")
lyr = ("Boundary_Selection.lyr")
arcpy.ApplySymbologyFromLayer_management (lyr, SymbologyLayer)

#Set Layers data frame extent and scale
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
lyr = arcpy.mapping.ListLayers(mxd, "Boundary", df)[0]
df.extent = lyr.getSelectedExtent(False)
df.scale = df.scale * 1.15


#Refresh map to show changes
arcpy.RefreshActiveView()
arcpy.RefreshTOC()

###################################################################

#Clip Soils layer, **goes to default gdb**
arcpy.Clip_analysis("Soils", "Boundary_Selection.lyr", "SoilsClip")


#Insert Layer below Boundary_Selection
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
refLayer = arcpy.mapping.ListLayers(mxd, "Boundary", df)[0]
insertLayer = arcpy.mapping.Layer("SoilsClip")
arcpy.mapping.InsertLayer(df, refLayer, insertLayer, "AFTER")

#Set Soils Clip Layer symbology
#SymbologyLayer = ("Soils")
#lyr = ("SoilsClip")
#arcpy.ApplySymbologyFromLayer_management (lyr, SymbologyLayer)

#Refresh map to show changes
arcpy.RefreshActiveView()
arcpy.RefreshTOC()

#Update SoilsClip Layer
arcpy.mapping.UpdateLayer("Layers", "SoilsClip", "Soils", False)

#Refresh map to show changes
arcpy.RefreshActiveView()
arcpy.RefreshTOC()

mxd.save()
del mxd,
Tags (2)
0 Kudos
1 Reply
JeffMoulds
Esri Contributor
Instead of using strings for the input paramaters in UpdateLayer, use actual data frame and layer objects. For example:

arcpy.mapping.UpdateLayer(df, insertLayer, soilsLayer, False)

I noticed in your code, you already have a reference to a data frame and the SoilsClip layer - so you can use those, as I have above. However, you will also need to make a reference to the Soils layer, similar to how you referenced the SoilsClip layer.

Check out the syntax here for UpdateLayer: http://resources.arcgis.com/en/help/main/10.1/#/UpdateLayer/00s30000003p000000/. The paramater explanations have links to the Layer class help.
0 Kudos