<?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: Cast Feature Layer to Layer in Arcpy/Pro in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/cast-feature-layer-to-layer-in-arcpy-pro/m-p/1054986#M61046</link>
    <description>&lt;P&gt;See the code example.&amp;nbsp; Your layer will have the name "lyr"&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/layer-class.htm" target="_blank"&gt;Layer—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;a Layerfile is a *.lyr or *.lyrx on disk&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/layerfile-class.htm" target="_blank"&gt;LayerFile—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 06 May 2021 00:00:48 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2021-05-06T00:00:48Z</dc:date>
    <item>
      <title>Cast Feature Layer to Layer in Arcpy/Pro</title>
      <link>https://community.esri.com/t5/python-questions/cast-feature-layer-to-layer-in-arcpy-pro/m-p/1054959#M61045</link>
      <description>&lt;P&gt;Hello all. I have a script I am updating from ArcGIS Desktop (Python 2) to ArcGIS Pro (Python 3). As part of the older script I would cast a feature class as a feature layer via MakeFeatureLayer_management and then I would further cast that feature layer to a Layer object to get access to the layer's properties:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.MakeFeatureLayer_management(fc, "lyr")
lyr = arcpy.mapping.Layer("lyr")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;It appears that the Pro version of arcpy doesn't actually have a layer object in the mapping (mp) module anymore. So, if I were to do something similar:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.MakeFeatureLayer_management(fc, "lyr")
lyr = arcpy.mp.Layer("lyr")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;which returns:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;AttributeError: module 'arcpy.mp' has no attribute 'Layer'&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I also tried:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.MakeFeatureLayer_management(fc, "lyr")
lyr = arcpy.mp.LayerFile("lyr")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and threw the error:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;ValueError: lyr&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;So, at the end of the day, I need to take a geodatabase feature class and somehow cast it as a layer in order to manipulate layer properties in arcpy for Pro. Any suggestion how I can do that. Points for avoiding saving the layer to disk.&lt;/P&gt;</description>
      <pubDate>Wed, 05 May 2021 22:55:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cast-feature-layer-to-layer-in-arcpy-pro/m-p/1054959#M61045</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2021-05-05T22:55:07Z</dc:date>
    </item>
    <item>
      <title>Re: Cast Feature Layer to Layer in Arcpy/Pro</title>
      <link>https://community.esri.com/t5/python-questions/cast-feature-layer-to-layer-in-arcpy-pro/m-p/1054986#M61046</link>
      <description>&lt;P&gt;See the code example.&amp;nbsp; Your layer will have the name "lyr"&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/layer-class.htm" target="_blank"&gt;Layer—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;a Layerfile is a *.lyr or *.lyrx on disk&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/layerfile-class.htm" target="_blank"&gt;LayerFile—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 May 2021 00:00:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cast-feature-layer-to-layer-in-arcpy-pro/m-p/1054986#M61046</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-05-06T00:00:48Z</dc:date>
    </item>
    <item>
      <title>Re: Cast Feature Layer to Layer in Arcpy/Pro</title>
      <link>https://community.esri.com/t5/python-questions/cast-feature-layer-to-layer-in-arcpy-pro/m-p/1055049#M61047</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;The best way I found to do it is to use&amp;nbsp;arcpy.SaveToLayerFile_management on the feature layer into some temporary folder. Then use the lyrx that was created to create a arcpy.mp.LayerFile&lt;/P&gt;&lt;P&gt;Not very elegant but does the work and does not take too much time.&lt;/P&gt;&lt;P&gt;Have Fun&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 May 2021 05:13:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cast-feature-layer-to-layer-in-arcpy-pro/m-p/1055049#M61047</guid>
      <dc:creator>mody_buchbinder</dc:creator>
      <dc:date>2021-05-06T05:13:47Z</dc:date>
    </item>
    <item>
      <title>Re: Cast Feature Layer to Layer in Arcpy/Pro</title>
      <link>https://community.esri.com/t5/python-questions/cast-feature-layer-to-layer-in-arcpy-pro/m-p/1055062#M61048</link>
      <description>&lt;P&gt;Just use the layer object returned by the MakeFeatureLayer result:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;layer = arcpy.management.MakeFeatureLayer(fc, "lyr")[0]
layer
&amp;lt;arcpy._mp.Layer object at 0x0000023785BDD080&amp;gt;
layer.name
'lyr'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't have access to Desktop/ArcMap to test if the `[0]` indexing works like it does in Pro, but you could have used something like the following in ArcMap instead of casting:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;layer = arcpy.MakeFeatureLayer_management(fc, "lyr").getOutput(0)&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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 May 2021 12:36:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cast-feature-layer-to-layer-in-arcpy-pro/m-p/1055062#M61048</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2021-05-06T12:36:44Z</dc:date>
    </item>
    <item>
      <title>Re: Cast Feature Layer to Layer in Arcpy/Pro</title>
      <link>https://community.esri.com/t5/python-questions/cast-feature-layer-to-layer-in-arcpy-pro/m-p/1055246#M61058</link>
      <description>&lt;P&gt;Hey Dan. I looked at the code examples before, however to get to a single layer, it appears that you have to list out the maps from a project and then list the layers out. The examples don't speak to casting directly to a layer object without listing them out from some source. For example in the Desktop &lt;A href="https://desktop.arcgis.com/en/arcmap/10.6/analyze/arcpy-mapping/layer-class.htm" target="_self"&gt;help doc&lt;/A&gt;, example #1 on the second line, it shows how to grab a layerfile and cast it as directly as a layer object via arcpy.mapping.Layer.I find it odd that Pro arcpy does not have that layer object in the new mapping class.&lt;/P&gt;</description>
      <pubDate>Thu, 06 May 2021 15:18:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cast-feature-layer-to-layer-in-arcpy-pro/m-p/1055246#M61058</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2021-05-06T15:18:42Z</dc:date>
    </item>
    <item>
      <title>Re: Cast Feature Layer to Layer in Arcpy/Pro</title>
      <link>https://community.esri.com/t5/python-questions/cast-feature-layer-to-layer-in-arcpy-pro/m-p/1055247#M61059</link>
      <description>&lt;P&gt;Thanks. Yes, so far that's the only way I can see doing this, at this point. It's not how I want to handle the data, so I'm hoping to avoid saving to disk.&lt;/P&gt;</description>
      <pubDate>Thu, 06 May 2021 15:20:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cast-feature-layer-to-layer-in-arcpy-pro/m-p/1055247#M61059</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2021-05-06T15:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: Cast Feature Layer to Layer in Arcpy/Pro</title>
      <link>https://community.esri.com/t5/python-questions/cast-feature-layer-to-layer-in-arcpy-pro/m-p/1055262#M61060</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/10780"&gt;@Luke_Pinner&lt;/a&gt; I am forgetting the subtleties of the switch to Pro. I didn't realized there was a sub-module for 'management' now as opposed to direct calls to Data Management tools. i.e.&lt;/P&gt;&lt;P&gt;Desktop 10.x:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.MakeFeatureLayer_management&lt;/LI-CODE&gt;&lt;P&gt;vs ArcGIS Pro:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.management.MakeFeatureLayer&lt;/LI-CODE&gt;&lt;P&gt;And nice call on the indexing of the layer object too. That's not something I would have intuitively thought to do.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;</description>
      <pubDate>Thu, 06 May 2021 15:56:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cast-feature-layer-to-layer-in-arcpy-pro/m-p/1055262#M61060</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2021-05-06T15:56:40Z</dc:date>
    </item>
    <item>
      <title>Re: Cast Feature Layer to Layer in Arcpy/Pro</title>
      <link>https://community.esri.com/t5/python-questions/cast-feature-layer-to-layer-in-arcpy-pro/m-p/1055290#M61063</link>
      <description>&lt;P&gt;Mike&lt;/P&gt;&lt;P&gt;&amp;nbsp;MakeFeatureLayer_management or&amp;nbsp;arcpy.management.MakeFeatureLayer&lt;/P&gt;&lt;P&gt;both work in Pro&lt;/P&gt;</description>
      <pubDate>Thu, 06 May 2021 16:45:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cast-feature-layer-to-layer-in-arcpy-pro/m-p/1055290#M61063</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-05-06T16:45:54Z</dc:date>
    </item>
    <item>
      <title>Re: Cast Feature Layer to Layer in Arcpy/Pro</title>
      <link>https://community.esri.com/t5/python-questions/cast-feature-layer-to-layer-in-arcpy-pro/m-p/1055503#M61067</link>
      <description>&lt;P&gt;arcpy.subpackage.Tool and arcpy.Tool_subpackage works in both Pro and Desktop.&lt;/P&gt;</description>
      <pubDate>Thu, 06 May 2021 23:01:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cast-feature-layer-to-layer-in-arcpy-pro/m-p/1055503#M61067</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2021-05-06T23:01:44Z</dc:date>
    </item>
    <item>
      <title>Re: Cast Feature Layer to Layer in Arcpy/Pro</title>
      <link>https://community.esri.com/t5/python-questions/cast-feature-layer-to-layer-in-arcpy-pro/m-p/1055518#M61069</link>
      <description>&lt;P&gt;another example here&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/python-questions/script-stopped-working-properly-with-upgrade-of-arcgis-pro/m-p/1055514#M61068" target="_blank"&gt;Re: Script stopped working properly with upgrade o... - Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;All paths lead to the same destination&lt;/P&gt;&lt;P&gt;In fact, if one is interested in the scripts follow the trail&amp;nbsp; for MakeFeatureLayer&lt;/P&gt;&lt;P&gt;Toolbox location&lt;/P&gt;&lt;P&gt;C:\...Install_Folder...\Resources\ArcToolBox\toolboxes&lt;/P&gt;&lt;P&gt;C:\...Install_Folder...\Resources\ArcToolBox\toolboxes\Data Management Tools.tbx\MakeFeatureLayer.tool&lt;/P&gt;&lt;P&gt;Script and function location&lt;/P&gt;&lt;P&gt;C:\...Install_Folder...\Resources\ArcPy\arcpy\management.py&lt;/P&gt;</description>
      <pubDate>Thu, 06 May 2021 23:35:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cast-feature-layer-to-layer-in-arcpy-pro/m-p/1055518#M61069</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-05-06T23:35:38Z</dc:date>
    </item>
    <item>
      <title>Re: Cast Feature Layer to Layer in Arcpy/Pro</title>
      <link>https://community.esri.com/t5/python-questions/cast-feature-layer-to-layer-in-arcpy-pro/m-p/1191031#M64975</link>
      <description>&lt;P&gt;Somewhat related: &lt;A href="https://community.esri.com/t5/python-questions/how-to-access-layer-properties-from-a/m-p/1191018#M64974" target="_blank"&gt;https://community.esri.com/t5/python-questions/how-to-access-layer-properties-from-a/m-p/1191018#M64974&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 22:20:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cast-feature-layer-to-layer-in-arcpy-pro/m-p/1191031#M64975</guid>
      <dc:creator>SamSzotkowski</dc:creator>
      <dc:date>2022-07-08T22:20:24Z</dc:date>
    </item>
  </channel>
</rss>

