<?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: layer object vs. layer name in Python Snippets Questions</title>
    <link>https://community.esri.com/t5/python-snippets-questions/layer-object-vs-layer-name/m-p/825207#M371</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I discuss this a bit in a blog post:&amp;nbsp; &lt;A href="https://community.esri.com/blogs/tilting/2014/08/19/whats-in-a-data-type-when-featureclass-string"&gt;/blogs/tilting/2014/08/19/whats-in-a-data-type-when-featureclass-string&lt;/A&gt; .&amp;nbsp; The way I usually approach it is that the documentation for native ArcPy functions, like &lt;SPAN style="font-family: courier new,courier,monospace;"&gt;arcpy.mapping.ListLayers()&lt;/SPAN&gt;, is much truer to the data type the function, method, or property needs while the documentation for Geoprocessing functions, like &lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;arcpy.SelectLayerByAttribute_management,&amp;nbsp;&lt;/SPAN&gt; tends to state the type of object the string name you pass refers back to.&amp;nbsp; The documentation is fairly consistent within each group/type of ArcPy functions, it just isn't consistent between the two groups/types themselves.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I agree with Dan, you get used to it, but I still think it is sloppy on Esri's part.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 06 Oct 2017 15:23:02 GMT</pubDate>
    <dc:creator>JoshuaBixby</dc:creator>
    <dc:date>2017-10-06T15:23:02Z</dc:date>
    <item>
      <title>layer object vs. layer name</title>
      <link>https://community.esri.com/t5/python-snippets-questions/layer-object-vs-layer-name/m-p/825205#M369</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't understand when an input argument to an arcpy function that says it takes a layer as an input but it really only works when I give it the name of the layer. Specifically: I use the arcpy.mapping.ListLayers() function to get a list of all the 'layers' in my mxd. I then search through this list to find the layer for which the .name value of the layer I'm interested in. I then copy this layer object out of the list returned by ListLayers(). I assume that what I have is a layer in the sense of what's documented on this page:&amp;nbsp;&lt;A class="link-titled" href="http://desktop.arcgis.com/en/arcmap/10.4/analyze/arcpy-mapping/layer-class.htm" title="http://desktop.arcgis.com/en/arcmap/10.4/analyze/arcpy-mapping/layer-class.htm"&gt;Layer—Help | ArcGIS Desktop&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I then read the documentation for the SelectLayerByAttribute_management() at:&amp;nbsp;&lt;A class="link-titled" href="http://desktop.arcgis.com/en/arcmap/10.4/tools/data-management-toolbox/select-layer-by-attribute.htm" title="http://desktop.arcgis.com/en/arcmap/10.4/tools/data-management-toolbox/select-layer-by-attribute.htm"&gt;Select Layer By Attribute—Help | ArcGIS Desktop&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and it looks like it says that it takes a 'Layer' as it's first argument.&amp;nbsp; So I call arcpy.SelectLayerByAttribute_management() handing it my layer object (from above) and the second argument of "CLEAR_SELECTIONS".&amp;nbsp; The error message I get back is "ERROR 000732: Layer Name or Table View: Dataset GPL0 does not exist or is not supported".&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so, it seems I just called a function that wants a layer as its first argument and I hand it a layer object that arcpy handed to me, and the function barks.&amp;nbsp; So I try using the string value of the layer name as the first argument and now the function works like a charm! So, if a string value of the layer's name that I want to clear selections for is what the function wants, then why doesn't the documentation say the the first argument is a string value, instead of a layer object?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Python snippet:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;mxd = arcpy.mapping.MapDocument("CURRENT")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;main_frames = arcpy.mapping.ListDataFrames(mxd,"Layers")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;main_frame = main_frames[0]&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;main_layers = layers = arcpy.mapping.ListLayers(mxd,"*",main_frame)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;for lay in main_layers:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;if lay.name == 'Report Polygons':&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rpolys = lay&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;rpolys.isFeatureLayer&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;# this is 'True'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;rpolys.isBroken&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;# this is 'False'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;rpolys.isGroupLayer&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;# this is 'False'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;rpolys.serviceProperties['Is_Geodatabase']&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;# this has the value 'true'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;arcpy.SelectLayerByAttribute_management(rpolys,"CLEAR_SELECTION")&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;# this fails&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;arcpy.SelectLayerByAttribute_management(rpolys.name,"CLEAR_SELECTION")&amp;nbsp;&amp;nbsp;# this gives me a &amp;lt;Result&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This seems to be the case for many of the arcpy functions that claim to take a 'Layer' as an input argument - all they &lt;EM&gt;really&lt;/EM&gt; want is a string that contains the name of the layer.&lt;/P&gt;&lt;P&gt;Is it a fools errand to search my mxd for the layer I want to use when it appears that functions like SelectLayerByAttribute_management() will do it for me?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Oct 2017 18:46:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/layer-object-vs-layer-name/m-p/825205#M369</guid>
      <dc:creator>GeorgeRiner</dc:creator>
      <dc:date>2017-10-05T18:46:51Z</dc:date>
    </item>
    <item>
      <title>Re: layer object vs. layer name</title>
      <link>https://community.esri.com/t5/python-snippets-questions/layer-object-vs-layer-name/m-p/825206#M370</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree with the sometimes conflicting information.&amp;nbsp; I rapidly learned to use the code examples for guidance rather than the tabular description of parameters.&amp;nbsp; I think part of the problem lies in the reluctance to name the parameters directly (ie layer versus layername). It is no consolation but you will eventually get used to it&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Oct 2017 09:41:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/layer-object-vs-layer-name/m-p/825206#M370</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-10-06T09:41:50Z</dc:date>
    </item>
    <item>
      <title>Re: layer object vs. layer name</title>
      <link>https://community.esri.com/t5/python-snippets-questions/layer-object-vs-layer-name/m-p/825207#M371</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I discuss this a bit in a blog post:&amp;nbsp; &lt;A href="https://community.esri.com/blogs/tilting/2014/08/19/whats-in-a-data-type-when-featureclass-string"&gt;/blogs/tilting/2014/08/19/whats-in-a-data-type-when-featureclass-string&lt;/A&gt; .&amp;nbsp; The way I usually approach it is that the documentation for native ArcPy functions, like &lt;SPAN style="font-family: courier new,courier,monospace;"&gt;arcpy.mapping.ListLayers()&lt;/SPAN&gt;, is much truer to the data type the function, method, or property needs while the documentation for Geoprocessing functions, like &lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;arcpy.SelectLayerByAttribute_management,&amp;nbsp;&lt;/SPAN&gt; tends to state the type of object the string name you pass refers back to.&amp;nbsp; The documentation is fairly consistent within each group/type of ArcPy functions, it just isn't consistent between the two groups/types themselves.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I agree with Dan, you get used to it, but I still think it is sloppy on Esri's part.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Oct 2017 15:23:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/layer-object-vs-layer-name/m-p/825207#M371</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2017-10-06T15:23:02Z</dc:date>
    </item>
    <item>
      <title>Re: layer object vs. layer name</title>
      <link>https://community.esri.com/t5/python-snippets-questions/layer-object-vs-layer-name/m-p/825208#M372</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Taking this another step then ...&lt;/P&gt;&lt;P&gt;I was trying to make interactive debugging possible while developing an arcpy tool. (interspersing my code with bits of arcpy.AddMessage() to output variable values is so ... 1970's; i.e. lame.) It is apparently well known that running the python debugging IDE takes you away from the current map document in which the tool is invoked.&amp;nbsp; I.e., references to layers by only their name works fine if the current map document is available but not when debugging because there is no 'current map document' available.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there some mysterious undocumented 'environment'-like value that indicates what the current map document is?&amp;nbsp; If I could set this, then references to layers by namestring could work.&amp;nbsp; But I can't find a way to set this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was hoping that if a tool says it takes a 'layer' as input, that it really meant a layer object and that object could refer to a layer in the current map document or a layer object obtained from an 'external' map document. But arcpy tools that take layer names apparently only search for those names in the 'current' map document; and when I'm in the interactive debugger then there is no current map document.&amp;nbsp; This is dumb. Why can't I just set the current map document and get a working context during debugging??&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Feb 2018 19:57:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/layer-object-vs-layer-name/m-p/825208#M372</guid>
      <dc:creator>GeorgeRiner</dc:creator>
      <dc:date>2018-02-07T19:57:02Z</dc:date>
    </item>
  </channel>
</rss>

