<?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 Re: renaming a layer thats just been created in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/renaming-a-layer-thats-just-been-created/m-p/374202#M29548</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The lyr.name = "NewName" seems to work, but the layer is removed from the TOC.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Basic Code below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Import arcpy module&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd = arcpy.mapping.MapDocument("CURRENT")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;df = arcpy.mapping.ListDataFrames(mxd)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;lyr = arcpy.mapping.ListLayers(mxd)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;lyr.name = "NewName"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.RefreshTOC()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Has anyone else had this problem, and has come up with a solution?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I will note that if you enter these lines directly into the command prompt they work fine, BUT&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if you inport the python script into a Toolbox there is a problem with the layer being removed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be appreciated.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 30 Dec 2011 17:23:44 GMT</pubDate>
    <dc:creator>StephenLong</dc:creator>
    <dc:date>2011-12-30T17:23:44Z</dc:date>
    <item>
      <title>renaming a layer thats just been created</title>
      <link>https://community.esri.com/t5/python-questions/renaming-a-layer-thats-just-been-created/m-p/374200#M29546</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am creating a layer with python, is there a way of renaming it immediately or a way to identify what layer was just added so I can rename it, see code below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd = arcpy.mapping.MapDocument("CURRENT")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;df = arcpy.mapping.ListDataFrames(mxd)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;layers = arcpy.mapping.ListLayers(mxd, "", df)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;words = ['curpm1', 'curpm2', 'curpm3']&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for word in words:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print word&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; groupLayer = arcpy.mapping.Layer(r"C:\Users\oliverm\Desktop\GIS1\GL1.lyr")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df, groupLayer, "BOTTOM")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;STRONG&gt;&amp;nbsp; 'rename layer here'&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you very much for your help, I ideally want to be able to create the newly added layer as one of the list words.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Oliver&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 14:28:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/renaming-a-layer-thats-just-been-created/m-p/374200#M29546</guid>
      <dc:creator>OliverMorris</dc:creator>
      <dc:date>2011-12-20T14:28:26Z</dc:date>
    </item>
    <item>
      <title>Re: renaming a layer thats just been created</title>
      <link>https://community.esri.com/t5/python-questions/renaming-a-layer-thats-just-been-created/m-p/374201#M29547</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You can use the layer Name property as it is read/write for that layer file. This provides the ability to set or get the name of a layer the way it would appear in the ArcMap table of contents. Spaces can be included. All layer types support this property. Check out &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Layer/00s300000008000000/" rel="nofollow noopener noreferrer" target="_blank"&gt;the layer class page&lt;/A&gt;&lt;SPAN&gt; for more information about the name property and the others you can call on a layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You will probably want to loop through your layers but then you can use something like this to see the layer name: &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for lyr in layers:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print lyr.name&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:18:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/renaming-a-layer-thats-just-been-created/m-p/374201#M29547</guid>
      <dc:creator>StephanieWendel</dc:creator>
      <dc:date>2021-12-11T17:18:49Z</dc:date>
    </item>
    <item>
      <title>Re: renaming a layer thats just been created</title>
      <link>https://community.esri.com/t5/python-questions/renaming-a-layer-thats-just-been-created/m-p/374202#M29548</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The lyr.name = "NewName" seems to work, but the layer is removed from the TOC.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Basic Code below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Import arcpy module&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd = arcpy.mapping.MapDocument("CURRENT")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;df = arcpy.mapping.ListDataFrames(mxd)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;lyr = arcpy.mapping.ListLayers(mxd)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;lyr.name = "NewName"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.RefreshTOC()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Has anyone else had this problem, and has come up with a solution?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I will note that if you enter these lines directly into the command prompt they work fine, BUT&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if you inport the python script into a Toolbox there is a problem with the layer being removed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be appreciated.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Dec 2011 17:23:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/renaming-a-layer-thats-just-been-created/m-p/374202#M29548</guid>
      <dc:creator>StephenLong</dc:creator>
      <dc:date>2011-12-30T17:23:44Z</dc:date>
    </item>
    <item>
      <title>Re: renaming a layer thats just been created</title>
      <link>https://community.esri.com/t5/python-questions/renaming-a-layer-thats-just-been-created/m-p/374203#M29549</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This is a know issue (NIM070882) and will be addressed in SP4.&amp;nbsp; In the meantime, run your script as a stand-alone script (i.e., not using CURRENT) and it should work fine.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Jan 2012 13:38:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/renaming-a-layer-thats-just-been-created/m-p/374203#M29549</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2012-01-03T13:38:40Z</dc:date>
    </item>
  </channel>
</rss>

