CaspianKid

UpdateLayer Assertion Error

Discussion created by CaspianKid on Jul 2, 2012
Latest reply on Jul 2, 2012 by jmoulds-esristaff
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,

Outcomes