<?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: Sort layers in TOC using arcpy in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/sort-layers-in-toc-using-arcpy/m-p/29075#M2243</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;in this project i don't need to sort &lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;geometry first. I do need to sort &lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;alphabetically and also by numbers. &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 31 Dec 2015 14:43:13 GMT</pubDate>
    <dc:creator>Yaron_YosefCohen</dc:creator>
    <dc:date>2015-12-31T14:43:13Z</dc:date>
    <item>
      <title>Sort layers in TOC using arcpy</title>
      <link>https://community.esri.com/t5/python-questions/sort-layers-in-toc-using-arcpy/m-p/29072#M2240</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;i try to sort layers in the TOC, in &lt;SPAN style="color: #222426; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; background-color: rgba(248, 248, 248, 0.6);"&gt;ascending or by name alphbetical&lt;/SPAN&gt; with this code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

mxd = arcpy.mapping.MapDocument(r"D:\desktop\Project\project.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0] # Assuming one data frame
group_lyr = [lyr for lyr in arcpy.mapping.ListLayers(mxd) if lyr.isGroupLayer][0] # The temp group layer should be the only one
lyr_names = sorted(lyr.name for lyr in arcpy.mapping.ListLayers(mxd) if lyr.isFeatureLayer)
for name in lyr_names:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.MoveLayer(df, group_lyr, arcpy.mapping.ListLayers(mxd, name)[0], "BEFORE")
&amp;nbsp;&amp;nbsp;&amp;nbsp; print name +' sorted'
&amp;nbsp;&amp;nbsp; 
arcpy.mapping.RemoveLayer(df, group_lyr)&lt;/PRE&gt;&lt;P&gt;and got:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; 
land use sorted
river sorted
&amp;gt;&amp;gt;&amp;gt; &lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but the TOC do't sorted. For clarity, i saw this question in &lt;A href="http://gis.stackexchange.com/questions/43810/arc-gis-10-1-how-to-sort-layers-ascending-at-toc-in-list-by-drawing-order" title="http://gis.stackexchange.com/questions/43810/arc-gis-10-1-how-to-sort-layers-ascending-at-toc-in-list-by-drawing-order" rel="nofollow noopener noreferrer" target="_blank"&gt;arcgis 10.0 - Arc GIS 10.1 - How to sort Layers ascending at TOC in "List by drawing order" - Geographic Information Sys…&lt;/A&gt; &lt;/P&gt;&lt;P&gt;I work with arc view 10.3. I know it possible with extension, but i have no extensions.&lt;/P&gt;&lt;P&gt;Is it possible to do it with python?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:10:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sort-layers-in-toc-using-arcpy/m-p/29072#M2240</guid>
      <dc:creator>Yaron_YosefCohen</dc:creator>
      <dc:date>2021-12-10T21:10:21Z</dc:date>
    </item>
    <item>
      <title>Re: Sort layers in TOC using arcpy</title>
      <link>https://community.esri.com/t5/python-questions/sort-layers-in-toc-using-arcpy/m-p/29073#M2241</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't see where you saved the document. You may want to use savACopy() till you get what you want.&lt;/P&gt;&lt;P&gt;&lt;A href="http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-mapping/mapdocument-class.htm" title="http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-mapping/mapdocument-class.htm"&gt;MapDocument—Help | ArcGIS for Desktop&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Dec 2015 13:07:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sort-layers-in-toc-using-arcpy/m-p/29073#M2241</guid>
      <dc:creator>WesMiller</dc:creator>
      <dc:date>2015-12-31T13:07:23Z</dc:date>
    </item>
    <item>
      <title>Re: Sort layers in TOC using arcpy</title>
      <link>https://community.esri.com/t5/python-questions/sort-layers-in-toc-using-arcpy/m-p/29074#M2242</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;also, it makes little sense to sort things alphabetically... for example&lt;/P&gt;&lt;P&gt;...&amp;nbsp; landuse, river&amp;nbsp;&amp;nbsp; in this scenario, you could have agricultural land over top of the river&lt;/P&gt;&lt;P&gt;...&amp;nbsp; fire station, ownership .... where did the fire station go?&lt;/P&gt;&lt;P&gt;... bridge, river .... the Chunnel?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Order things by geometry first, then conceptually within each grouping to ensure that you don't obliterate features that should be seen&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Dec 2015 14:15:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sort-layers-in-toc-using-arcpy/m-p/29074#M2242</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-12-31T14:15:13Z</dc:date>
    </item>
    <item>
      <title>Re: Sort layers in TOC using arcpy</title>
      <link>https://community.esri.com/t5/python-questions/sort-layers-in-toc-using-arcpy/m-p/29075#M2243</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;in this project i don't need to sort &lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;geometry first. I do need to sort &lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;alphabetically and also by numbers. &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Dec 2015 14:43:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sort-layers-in-toc-using-arcpy/m-p/29075#M2243</guid>
      <dc:creator>Yaron_YosefCohen</dc:creator>
      <dc:date>2015-12-31T14:43:13Z</dc:date>
    </item>
  </channel>
</rss>

