robdicker

Problem with UpdateLayer

Discussion created by robdicker on May 30, 2014
Latest reply on Jun 2, 2014 by robdicker
I'm trying to update a polygon layer from some default symbology held in a group layer in an mxd file. The polygon shape file is created from a raster immediately before I try to apply the default symbology. However, the program does not recognise the new shape file as a layer and therefore fails.

My understanding is that I do not have to explicitly save the shape file as a layer before trying to update it with new symbology. Therefore after the shape file is created it should be the first layer in the mxd. In the following script the source layer is the fifth layer inside the the group layer of symbology

# set environment setting to overwrite output
arcpy.env.overwriteOutput = True
# add outputs to map
arcpy.env.addOutputsToMap = True
# set workspace
arcpy.env.workspace = r'C:\Temp\myfile'

mxd = arcpy.mapping.MapDocument(r'C:\Temp\myfile\mymxd.mxd')
df = arcpy.mapping.ListDataFrames(mxd)[0]
       

inRaster = 'hSr_' + str(azimuth) + '_' + str(altitude)
outPolygons = str(azimuth) + '_' + str(altitude) + '.shp'
field = 'VALUE'
# Execute RasterToPolygon
arcpy.RasterToPolygon_conversion(inRaster, outPolygons, 'SIMPLIFY', field)

# this works fine up to here but fails at UpdateLayer

updateLayer = arcpy.mapping.ListLayers(mxd)[0]
sourceLayer = arcpy.mapping.ListLayers(mxd)[7]
arcpy.mapping.UpdateLayer(df, updateLayer, sourceLayer, True)
mxd.save()

This generates the following error:

LayerObject: Unexpected error

Any help with this would be appreciated.

Outcomes