<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Problem with UpdateLayer in Mapping Questions</title>
    <link>https://community.esri.com/t5/mapping-questions/problem-with-updatelayer/m-p/255612#M2718</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# set environment setting to overwrite output&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.overwriteOutput = True&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# add outputs to map&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.addOutputsToMap = True&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# set workspace&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.workspace = r'C:\Temp\myfile'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd = arcpy.mapping.MapDocument(r'C:\Temp\myfile\mymxd.mxd')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;df = arcpy.mapping.ListDataFrames(mxd)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;inRaster = 'hSr_' + str(azimuth) + '_' + str(altitude)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;outPolygons = str(azimuth) + '_' + str(altitude) + '.shp'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;field = 'VALUE'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Execute RasterToPolygon&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.RasterToPolygon_conversion(inRaster, outPolygons, 'SIMPLIFY', field)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# this works fine up to here but fails at UpdateLayer&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;updateLayer = arcpy.mapping.ListLayers(mxd)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sourceLayer = arcpy.mapping.ListLayers(mxd)[7]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.mapping.UpdateLayer(df, updateLayer, sourceLayer, True)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd.save()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This generates the following error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;LayerObject: Unexpected error&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help with this would be appreciated.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 31 May 2014 04:13:21 GMT</pubDate>
    <dc:creator>RobertDicker</dc:creator>
    <dc:date>2014-05-31T04:13:21Z</dc:date>
    <item>
      <title>Problem with UpdateLayer</title>
      <link>https://community.esri.com/t5/mapping-questions/problem-with-updatelayer/m-p/255612#M2718</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# set environment setting to overwrite output&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.overwriteOutput = True&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# add outputs to map&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.addOutputsToMap = True&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# set workspace&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.workspace = r'C:\Temp\myfile'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd = arcpy.mapping.MapDocument(r'C:\Temp\myfile\mymxd.mxd')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;df = arcpy.mapping.ListDataFrames(mxd)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;inRaster = 'hSr_' + str(azimuth) + '_' + str(altitude)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;outPolygons = str(azimuth) + '_' + str(altitude) + '.shp'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;field = 'VALUE'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Execute RasterToPolygon&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.RasterToPolygon_conversion(inRaster, outPolygons, 'SIMPLIFY', field)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# this works fine up to here but fails at UpdateLayer&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;updateLayer = arcpy.mapping.ListLayers(mxd)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sourceLayer = arcpy.mapping.ListLayers(mxd)[7]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.mapping.UpdateLayer(df, updateLayer, sourceLayer, True)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd.save()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This generates the following error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;LayerObject: Unexpected error&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help with this would be appreciated.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 31 May 2014 04:13:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/problem-with-updatelayer/m-p/255612#M2718</guid>
      <dc:creator>RobertDicker</dc:creator>
      <dc:date>2014-05-31T04:13:21Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with UpdateLayer</title>
      <link>https://community.esri.com/t5/mapping-questions/problem-with-updatelayer/m-p/255613#M2719</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I can not see your layers, but perhaps you are miscounting the layers? The group counts as a layer item in the table of contents, SO if you had your first layer and then a group layer, and within the group layer you 3 layers, Roads, Streams, Houses, a pointer to the Houses layer would be [4]. You can verify the layer pointer with a simple print or arcpy.AddMessage statment like print arcpy.mapping.ListLayers(mxd)[7], and see if it returns what you expect.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Jim&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Jun 2014 17:42:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/problem-with-updatelayer/m-p/255613#M2719</guid>
      <dc:creator>JimCousins</dc:creator>
      <dc:date>2014-06-02T17:42:46Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with UpdateLayer</title>
      <link>https://community.esri.com/t5/mapping-questions/problem-with-updatelayer/m-p/255614#M2720</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Jim, the problem seems to me that even though I have set the addOutputsToMap = True, the shape file is not being added as a layer to the map document. Interestingly, when I tried using this script inside an Add In it appears to work but when deployed from a python IDE it doesn't?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Jun 2014 18:33:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/problem-with-updatelayer/m-p/255614#M2720</guid>
      <dc:creator>RobertDicker</dc:creator>
      <dc:date>2014-06-02T18:33:35Z</dc:date>
    </item>
  </channel>
</rss>

