<?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: Fail to Save Group Layer Using ArcPy in Stand Along Script in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/fail-to-save-group-layer-using-arcpy-in-stand/m-p/1215950#M60234</link>
    <description>&lt;P&gt;Hmm, works for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Save this script as a Python file in your project folder and run it:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
aprx_name = "Admin.aprx"
map_name = "Test"
lyr_name = "New Group Layer"

aprx = arcpy.mp.ArcGISProject(aprx_name)
m = aprx.listMaps(map_name)[0]
lyr = m.listLayers(lyr_name)[0]

arcpy.management.SaveToLayerFile(lyr, "test1.lyrx")
lyr.saveACopy("test2.lyrx")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 26 Sep 2022 07:06:57 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2022-09-26T07:06:57Z</dc:date>
    <item>
      <title>Fail to Save Group Layer Using ArcPy in Stand Along Script</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/fail-to-save-group-layer-using-arcpy-in-stand/m-p/1215924#M60229</link>
      <description>&lt;DIV&gt;&lt;SPAN&gt;It is succussed to save an empty group layer using following code in python window.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;arcpy&lt;/SPAN&gt;&lt;SPAN&gt;.management.SaveToLayerFile("Empty Group Layer"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;out_layer_path&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;None&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"CURRENT"&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;SPAN&gt;However, in stand along script environment, the saved layer file is invalid. I changed the keyword "Empty Group Layer" to a layer object from .aprx file opened via arcpy.mp. (from&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;aprx_map&lt;/SPAN&gt;&lt;SPAN&gt;.listLayers()&lt;/SPAN&gt;&lt;SPAN&gt;). Note: this empty group layer is manually generated in ArcGIS pro by right click MAP and click New Group Layer.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The documentation mentioned the input layer is a layer datatype that I assume this should work.&lt;/DIV&gt;&lt;DIV&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/save-to-layer-file.htm" target="_blank" rel="noopener"&gt;Save To Layer File (Data Management)—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Mon, 26 Sep 2022 04:14:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/fail-to-save-group-layer-using-arcpy-in-stand/m-p/1215924#M60229</guid>
      <dc:creator>ZhongyuYang</dc:creator>
      <dc:date>2022-09-26T04:14:30Z</dc:date>
    </item>
    <item>
      <title>Re: Fail to Save Group Layer Using ArcPy in Stand Along Script</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/fail-to-save-group-layer-using-arcpy-in-stand/m-p/1215950#M60234</link>
      <description>&lt;P&gt;Hmm, works for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Save this script as a Python file in your project folder and run it:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
aprx_name = "Admin.aprx"
map_name = "Test"
lyr_name = "New Group Layer"

aprx = arcpy.mp.ArcGISProject(aprx_name)
m = aprx.listMaps(map_name)[0]
lyr = m.listLayers(lyr_name)[0]

arcpy.management.SaveToLayerFile(lyr, "test1.lyrx")
lyr.saveACopy("test2.lyrx")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 07:06:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/fail-to-save-group-layer-using-arcpy-in-stand/m-p/1215950#M60234</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-09-26T07:06:57Z</dc:date>
    </item>
    <item>
      <title>Re: Fail to Save Group Layer Using ArcPy in Stand Along Script</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/fail-to-save-group-layer-using-arcpy-in-stand/m-p/1216054#M60260</link>
      <description>&lt;P&gt;Hi Johannes,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried your code.&amp;nbsp;&lt;SPAN&gt;"test1.lyrx" is&lt;STRONG&gt; invalid&lt;/STRONG&gt;. While "test2.lyrx" is valid (no problem to open or load into other project).&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Is it the same as you?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Zhongyu&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 14:05:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/fail-to-save-group-layer-using-arcpy-in-stand/m-p/1216054#M60260</guid>
      <dc:creator>ZhongyuYang</dc:creator>
      <dc:date>2022-09-26T14:05:02Z</dc:date>
    </item>
    <item>
      <title>Re: Fail to Save Group Layer Using ArcPy in Stand Along Script</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/fail-to-save-group-layer-using-arcpy-in-stand/m-p/1216058#M60262</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;Is it the same as you?&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;Nope, I can open both layers without problems. I don't know what the cause for your problem could be, but you could always just use the second method...&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 14:12:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/fail-to-save-group-layer-using-arcpy-in-stand/m-p/1216058#M60262</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-09-26T14:12:24Z</dc:date>
    </item>
  </channel>
</rss>

