<?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: Save Layer File with Python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/save-layer-file-with-python/m-p/298692#M23130</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Whoops! Replied at the same time again!&lt;/P&gt;&lt;P&gt;​&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 08 Apr 2015 02:19:15 GMT</pubDate>
    <dc:creator>SepheFox</dc:creator>
    <dc:date>2015-04-08T02:19:15Z</dc:date>
    <item>
      <title>Save Layer File with Python</title>
      <link>https://community.esri.com/t5/python-questions/save-layer-file-with-python/m-p/298685#M23123</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am working on a Multi-scale layer map using ArcMap.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since I have several hundred of different map layer in my *.mxd I'd like to save for each individual map layer a Layer File.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I found a script which already works but I'd like to get it to save the Layer Files for each Group Layer in a separate folder.&lt;/P&gt;&lt;P&gt;So all Layer Files should end up in a separate folder like the Group Layer is called in my *.mxd.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am not a coder and was already happy with the script I found but it would be great if somebody can help me with extending this script.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is the script I was using:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;CODE style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; color: #222222;"&gt;&lt;SPAN class="kwd" style="color: #8a4a0b;"&gt;import&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: #000000;"&gt; arcpy&lt;BR /&gt;mxd &lt;/SPAN&gt;&lt;SPAN class="pun" style="color: #145680;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: #000000;"&gt; arcpy&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: #145680;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: #000000;"&gt;mapping&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: #145680;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="typ" style="color: #2b91af;"&gt;MapDocument&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: #145680;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="str" style="color: #800000;"&gt;"CURRENT"&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: #145680;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: #000000;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN class="kwd" style="color: #8a4a0b;"&gt;for&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: #000000;"&gt; lyr &lt;/SPAN&gt;&lt;SPAN class="kwd" style="color: #8a4a0b;"&gt;in&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: #000000;"&gt; arcpy&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: #145680;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: #000000;"&gt;mapping&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: #145680;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="typ" style="color: #2b91af;"&gt;ListLayers&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: #145680;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: #000000;"&gt;mxd&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: #145680;"&gt;):&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: #000000;"&gt;&lt;BR /&gt;lyr&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: #145680;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: #000000;"&gt;saveACopy&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: #145680;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: #000000;"&gt;lyr&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: #145680;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: #000000;"&gt;name &lt;/SPAN&gt;&lt;SPAN class="pun" style="color: #145680;"&gt;+&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN class="str" style="color: #800000;"&gt;".lyr"&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: #145680;"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your help.&lt;/P&gt;&lt;P&gt;Pierre&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Apr 2015 02:07:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/save-layer-file-with-python/m-p/298685#M23123</guid>
      <dc:creator>PierreKurth</dc:creator>
      <dc:date>2015-04-02T02:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: Save Layer File with Python</title>
      <link>https://community.esri.com/t5/python-questions/save-layer-file-with-python/m-p/298686#M23124</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think you have to go back to &lt;A href="http://resources.arcgis.com/en/heLP/MAIN/10.2/index.html#/Layer/00s300000008000000/"&gt;layer properties within arcpy &lt;/A&gt;itself.&amp;nbsp; There are some code samples there that shows how to save layers with different names and saving locations.&amp;nbsp; You can modify a workflow based upon these values.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Apr 2015 03:31:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/save-layer-file-with-python/m-p/298686#M23124</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-04-02T03:31:36Z</dc:date>
    </item>
    <item>
      <title>Re: Save Layer File with Python</title>
      <link>https://community.esri.com/t5/python-questions/save-layer-file-with-python/m-p/298687#M23125</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you are doing this from the ArcMap Python window the following code should work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import os
basepath = r'G:\xTemp\MapLayers'
mxd = arcpy.mapping.MapDocument("CURRENT")
for lyr in arcpy.mapping.ListLayers(mxd):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.isGroupLayer == True:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; grpPath = os.path.join(basepath, &lt;SPAN style="color: rgba(0, 0, 0, 0); font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;str(lyr)&lt;/SPAN&gt;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not os.path.exists(grpPath):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; os.makedirs(grpPath)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fn = os.path.join(basepath, str(lyr) + ".lyr")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.saveACopy(fn)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Saved: " + fn&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just change the basepath to the output directory.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:20:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/save-layer-file-with-python/m-p/298687#M23125</guid>
      <dc:creator>OwenEarley</dc:creator>
      <dc:date>2021-12-11T14:20:20Z</dc:date>
    </item>
    <item>
      <title>Re: Save Layer File with Python</title>
      <link>https://community.esri.com/t5/python-questions/save-layer-file-with-python/m-p/298688#M23126</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you I appreciate your help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried this from the ArcMap Python window:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import os&lt;/P&gt;&lt;P&gt;basepath = r'N:\Temp\layerstyle'&lt;/P&gt;&lt;P&gt;mxd = arcpy.mapping.MapDocument("CURRENT")&lt;/P&gt;&lt;P&gt;for lyr in arcpy.mapping.ListLayers(mxd):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.isGroupLayer == True:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; grpPath = os.path.join(basepath, str(lyr))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not os.path.exists(grpPath):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; os.makedirs(grpPath)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fn = os.path.join(basepath, str(lyr) + ".lyr")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.saveACopy(fn)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Saved: " + fn&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Unfortunately it came back with an error message saying: &lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Parsing error SyntaxError : invalid syntax (line 6)&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I am not a Python coder so any help would be great.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2015 01:58:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/save-layer-file-with-python/m-p/298688#M23126</guid>
      <dc:creator>PierreKurth</dc:creator>
      <dc:date>2015-04-08T01:58:22Z</dc:date>
    </item>
    <item>
      <title>Re: Save Layer File with Python</title>
      <link>https://community.esri.com/t5/python-questions/save-layer-file-with-python/m-p/298689#M23127</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;​from the else statement onward it is indented too much, see the source example provided&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2015 02:03:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/save-layer-file-with-python/m-p/298689#M23127</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-04-08T02:03:31Z</dc:date>
    </item>
    <item>
      <title>Re: Save Layer File with Python</title>
      <link>https://community.esri.com/t5/python-questions/save-layer-file-with-python/m-p/298690#M23128</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The script is working now. Thank you very much it saved me a lot of time.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2015 02:13:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/save-layer-file-with-python/m-p/298690#M23128</guid>
      <dc:creator>PierreKurth</dc:creator>
      <dc:date>2015-04-08T02:13:45Z</dc:date>
    </item>
    <item>
      <title>Re: Save Layer File with Python</title>
      <link>https://community.esri.com/t5/python-questions/save-layer-file-with-python/m-p/298691#M23129</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Pierre, try replacing line six with &lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; grpPath = os.path.join(basepath, lyr)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;​and line ten with &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;fn = os.path.join(basepath, lyr + ".lyr")&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2015 02:17:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/save-layer-file-with-python/m-p/298691#M23129</guid>
      <dc:creator>SepheFox</dc:creator>
      <dc:date>2015-04-08T02:17:52Z</dc:date>
    </item>
    <item>
      <title>Re: Save Layer File with Python</title>
      <link>https://community.esri.com/t5/python-questions/save-layer-file-with-python/m-p/298692#M23130</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Whoops! Replied at the same time again!&lt;/P&gt;&lt;P&gt;​&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2015 02:19:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/save-layer-file-with-python/m-p/298692#M23130</guid>
      <dc:creator>SepheFox</dc:creator>
      <dc:date>2015-04-08T02:19:15Z</dc:date>
    </item>
    <item>
      <title>Re: Save Layer File with Python</title>
      <link>https://community.esri.com/t5/python-questions/save-layer-file-with-python/m-p/298693#M23131</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey pierre, can you mark this question as answered? This will help other people with the same problem find the answer. thanks!&lt;/P&gt;&lt;P&gt;​&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2015 02:46:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/save-layer-file-with-python/m-p/298693#M23131</guid>
      <dc:creator>SepheFox</dc:creator>
      <dc:date>2015-04-08T02:46:54Z</dc:date>
    </item>
  </channel>
</rss>

