<?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 Error trying to save layer from MXD to lyrx. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/error-trying-to-save-layer-from-mxd-to-lyrx/m-p/283649#M21895</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to load a layer from an mxd and back up the layer using ArcGIS Pro and Python.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;aprx.importDocument(current_document_name)
mlist = aprx.listMaps()
infra_layers = mlist[0].listLayers()
new_file_name = backup_geodatabase_path + 'ActiveInfraProjects.lyrx'
arcpy.SaveToLayerFile_management(infra_layers[0].name, new_file_name, 'ABSOLUTE')&lt;/PRE&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#I get the following error:

ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Layer: Dataset active_infrastructure_projects does not exist or is not supported
Failed to execute (SaveToLayerFile).

#It says it doesn't exist but I was able to get the name from the file (infra_layers[0]) so it must exist. 
#Why is it not supported?

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 16:17:25 GMT</pubDate>
    <dc:creator>SteveScott</dc:creator>
    <dc:date>2021-12-12T16:17:25Z</dc:date>
    <item>
      <title>Error trying to save layer from MXD to lyrx.</title>
      <link>https://community.esri.com/t5/python-questions/error-trying-to-save-layer-from-mxd-to-lyrx/m-p/283649#M21895</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to load a layer from an mxd and back up the layer using ArcGIS Pro and Python.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;aprx.importDocument(current_document_name)
mlist = aprx.listMaps()
infra_layers = mlist[0].listLayers()
new_file_name = backup_geodatabase_path + 'ActiveInfraProjects.lyrx'
arcpy.SaveToLayerFile_management(infra_layers[0].name, new_file_name, 'ABSOLUTE')&lt;/PRE&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#I get the following error:

ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Layer: Dataset active_infrastructure_projects does not exist or is not supported
Failed to execute (SaveToLayerFile).

#It says it doesn't exist but I was able to get the name from the file (infra_layers[0]) so it must exist. 
#Why is it not supported?

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:17:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-trying-to-save-layer-from-mxd-to-lyrx/m-p/283649#M21895</guid>
      <dc:creator>SteveScott</dc:creator>
      <dc:date>2021-12-12T16:17:25Z</dc:date>
    </item>
    <item>
      <title>Re: Error trying to save layer from MXD to lyrx.</title>
      <link>https://community.esri.com/t5/python-questions/error-trying-to-save-layer-from-mxd-to-lyrx/m-p/283650#M21896</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've just tried your code and it worked for me. So this leads me to wonder if the problem is in this line:&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;aprx&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;importDocument&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;current_document_name&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is this code in a loop and you are only showing us the salient commands? If so may be the loop is loading up a project with say a broken layer in it? Or you are have some sort of network connection issue?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Oct 2019 09:24:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-trying-to-save-layer-from-mxd-to-lyrx/m-p/283650#M21896</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2019-10-11T09:24:00Z</dc:date>
    </item>
    <item>
      <title>Re: Error trying to save layer from MXD to lyrx.</title>
      <link>https://community.esri.com/t5/python-questions/error-trying-to-save-layer-from-mxd-to-lyrx/m-p/283651#M21897</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;watch your path construction&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;# ---- not good&lt;/SPAN&gt;

backup_geodatabase_path &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;"c:\somefolder\some.gdb"&lt;/SPAN&gt;

new_file_name &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; backup_geodatabase_path &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'ActiveInfraProjects.lyrx'&lt;/SPAN&gt;

new_file_name
&lt;SPAN class="string token"&gt;'c:\\somefolder\\some.gdbActiveInfraProjects.lyrx'&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# ---- concatenate the bits simply&lt;/SPAN&gt;
args &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;backup_geodatabase_path&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'ActiveInfraProjects.lyrx'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

new_file_name &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"\\"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;join&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;a &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; a &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; args&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

new_file_name
&lt;SPAN class="string token"&gt;'c:\\somefolder\\some.gdb\\ActiveInfraProjects.lyrx'&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:43:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-trying-to-save-layer-from-mxd-to-lyrx/m-p/283651#M21897</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T13:43:31Z</dc:date>
    </item>
    <item>
      <title>Re: Error trying to save layer from MXD to lyrx.</title>
      <link>https://community.esri.com/t5/python-questions/error-trying-to-save-layer-from-mxd-to-lyrx/m-p/283652#M21898</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Or use os.path.join(var1,&amp;nbsp;var2, varetc) to construct paths to things&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Oct 2019 12:14:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-trying-to-save-layer-from-mxd-to-lyrx/m-p/283652#M21898</guid>
      <dc:creator>NeilAyres</dc:creator>
      <dc:date>2019-10-11T12:14:35Z</dc:date>
    </item>
    <item>
      <title>Re: Error trying to save layer from MXD to lyrx.</title>
      <link>https://community.esri.com/t5/python-questions/error-trying-to-save-layer-from-mxd-to-lyrx/m-p/283653#M21899</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You mention a loop. I am importing a single .mxd so why would it be in a loop?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Oct 2019 13:36:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-trying-to-save-layer-from-mxd-to-lyrx/m-p/283653#M21899</guid>
      <dc:creator>SteveScott</dc:creator>
      <dc:date>2019-10-11T13:36:49Z</dc:date>
    </item>
    <item>
      <title>Re: Error trying to save layer from MXD to lyrx.</title>
      <link>https://community.esri.com/t5/python-questions/error-trying-to-save-layer-from-mxd-to-lyrx/m-p/283654#M21900</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are missing all the import modules part of your script which would suggest to me that you are showing a cut down version hence me speculating how you are running this code. You don't state how you are running it. So I'm suggesting you are not showing us the bigger picture and the problem lies elsewhere as I was able to run your code without error.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Oct 2019 13:41:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-trying-to-save-layer-from-mxd-to-lyrx/m-p/283654#M21900</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2019-10-11T13:41:21Z</dc:date>
    </item>
    <item>
      <title>Re: Error trying to save layer from MXD to lyrx.</title>
      <link>https://community.esri.com/t5/python-questions/error-trying-to-save-layer-from-mxd-to-lyrx/m-p/283655#M21901</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;I needed to convert to a feature layer first.

arcpy.MakeFeatureLayer_management(infra_layers[0], "fl")
arcpy.CopyFeatures_management('fl', workspace_name)
arcpy.SaveToLayerFile_management(fl, new_file_name, 'ABSOLUTE')

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:17:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-trying-to-save-layer-from-mxd-to-lyrx/m-p/283655#M21901</guid>
      <dc:creator>SteveScott</dc:creator>
      <dc:date>2021-12-12T16:17:27Z</dc:date>
    </item>
  </channel>
</rss>

