<?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: arcpy.mp.LayerFile(layer_filename) hangs in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-mp-layerfile-layer-filename-hangs/m-p/1223087#M61246</link>
    <description>&lt;P&gt;A follow-up.&amp;nbsp; I have determined why calls to the following function sometimes hang indefinitely&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.mp.LayerFile(layer_filename)&lt;/LI-CODE&gt;&lt;P&gt;When the layers inside the given .lyr file have embedded database connection (Oracle in my case), but without embedded credentials, the above function call will hang.&amp;nbsp; A partial workaround is to set the following&amp;nbsp;&lt;/P&gt;&lt;P&gt;arcpy.env.workspace = path_to_sde_file&lt;/P&gt;&lt;P&gt;where the given .sde file path refers to a .sde file that has credentials embedded and which has an "instance" property that exactly matches what's in the .lyr file.&amp;nbsp; If the "instance" string is formatted even slightly differently, arcpy.mp.LayerFile(..) will hang.&lt;/P&gt;&lt;P&gt;Is anyone aware of a workaround so I can programmatically open .lyr files without being asked for db credentials?&amp;nbsp; (This was possible in arcpy for ArcGIS Desktop, but seems not currently possible in arcpy for ArcGIS Pro.)&lt;/P&gt;</description>
    <pubDate>Tue, 18 Oct 2022 22:06:01 GMT</pubDate>
    <dc:creator>banders</dc:creator>
    <dc:date>2022-10-18T22:06:01Z</dc:date>
    <item>
      <title>arcpy.mp.LayerFile(layer_filename) hangs</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-mp-layerfile-layer-filename-hangs/m-p/1217980#M60599</link>
      <description>&lt;P&gt;I am trying to upgrade an arcpy script written for ArcGIS Desktop to support ArcGIS Pro (2.9.4).&amp;nbsp;&lt;/P&gt;&lt;P&gt;The script needs to open an old-style .lyr file (not .lyrx), and then perform various operations on layers in that file.&lt;/P&gt;&lt;P&gt;For ArcGIS Desktop I did this:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; lyr_file = arcpy.mapping.Layer(lyr_filename)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The above command worked as expected in arcpy for ArcGIS Desktop.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;With ArcGIS Pro I am doing this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; lyr_file = arcpy.mp.LayerFile(lyr_filename)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The call to&amp;nbsp;arcpy.mp.LayerFile(..) hangs and seems to never return.&amp;nbsp; It's unclear to me why the function hangs.&amp;nbsp; One guess is that it's related to the fact that the .lyr file I am trying to access does not have data source connection info embedded.&amp;nbsp; (One of my goals is to set connection information after I open the file.)&amp;nbsp; Missing connection info wasn't a problem in ArcGIS Desktop, but perhaps it's a problem ArcGIS Pro??&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Sample script:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

layer_filename = r"..." #path to .lyr file without connection info embedded
print("the following function call never returns")
lyr_file = arcpy.mp.LayerFile(layer_filename)
print("this line is never reached")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions would be appreciated!&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2022 22:17:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpy-mp-layerfile-layer-filename-hangs/m-p/1217980#M60599</guid>
      <dc:creator>banders</dc:creator>
      <dc:date>2022-10-18T22:17:57Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.mp.LayerFile(layer_filename) hangs</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-mp-layerfile-layer-filename-hangs/m-p/1223087#M61246</link>
      <description>&lt;P&gt;A follow-up.&amp;nbsp; I have determined why calls to the following function sometimes hang indefinitely&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.mp.LayerFile(layer_filename)&lt;/LI-CODE&gt;&lt;P&gt;When the layers inside the given .lyr file have embedded database connection (Oracle in my case), but without embedded credentials, the above function call will hang.&amp;nbsp; A partial workaround is to set the following&amp;nbsp;&lt;/P&gt;&lt;P&gt;arcpy.env.workspace = path_to_sde_file&lt;/P&gt;&lt;P&gt;where the given .sde file path refers to a .sde file that has credentials embedded and which has an "instance" property that exactly matches what's in the .lyr file.&amp;nbsp; If the "instance" string is formatted even slightly differently, arcpy.mp.LayerFile(..) will hang.&lt;/P&gt;&lt;P&gt;Is anyone aware of a workaround so I can programmatically open .lyr files without being asked for db credentials?&amp;nbsp; (This was possible in arcpy for ArcGIS Desktop, but seems not currently possible in arcpy for ArcGIS Pro.)&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2022 22:06:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpy-mp-layerfile-layer-filename-hangs/m-p/1223087#M61246</guid>
      <dc:creator>banders</dc:creator>
      <dc:date>2022-10-18T22:06:01Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.mp.LayerFile(layer_filename) hangs</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-mp-layerfile-layer-filename-hangs/m-p/1306068#M70847</link>
      <description>&lt;P&gt;I want to use a view from an Enterprise Postgres db.&lt;BR /&gt;From ArcGis Pro 3.1 it'a all ok:&lt;BR /&gt;- the ".sde" is ok.&lt;BR /&gt;- I can import the "Database Feature Class" (that is my view in Postgres) to a new Map&lt;BR /&gt;with "Make Query Layer" tool.&lt;BR /&gt;&lt;BR /&gt;Now I want to reproduce the same with arcpy :&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.env.workspace = &amp;lt;sde_connection&amp;gt;

arcpy.MakeQueryLayer_management(
	input_database = &amp;lt;sde_connection&amp;gt;,
	out_layer_name = &amp;lt;out_lyr&amp;gt;,
	query = "select * from " + &amp;lt;pg_view_name&amp;gt;,
	oid_fields = [&amp;lt;oidfield_name&amp;gt;] ,
	shape_type = "POLYGON",
	srid = &amp;lt;srid_view&amp;gt;)

arcpy.SaveToLayerFile_management(
	in_layer = &amp;lt;out_lyr&amp;gt;,
	out_layer = &amp;lt;folder_proj&amp;gt; + &amp;lt;out_lyr&amp;gt; + ".lirx")

newLyr = arcpy.mp.LayerFile(
    layer_file_path = &amp;lt;folder_proj&amp;gt; + &amp;lt;out_lyr&amp;gt; + ".lirx")

&amp;lt;map_obj&amp;gt;.addLayer(
    add_layer_or_layerfile = newLyr)&lt;/LI-CODE&gt;&lt;P&gt;This is the Python error:&lt;/P&gt;&lt;LI-SPOILER&gt;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_mp.py", line 1304, in __init__&lt;BR /&gt;self._arc_object = arcgisscripting._mapping.LayerFile(*gp_fixargs((layer_file_path,), True))&lt;BR /&gt;ValueError: &amp;lt;absolute_lirx_path&amp;gt;&lt;/LI-SPOILER&gt;&lt;P&gt;In ArcGis Pro 3.1 I can add the .lirx file (SaveToLayerFile result)&lt;BR /&gt;to a new map (so the .lirx file seems to be correct).&lt;/P&gt;&lt;P&gt;What wrong with the code?&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2023 09:49:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpy-mp-layerfile-layer-filename-hangs/m-p/1306068#M70847</guid>
      <dc:creator>andy_gio</dc:creator>
      <dc:date>2023-07-06T09:49:33Z</dc:date>
    </item>
  </channel>
</rss>

