<?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: The attribute 'name' is not supported on an instance of Layer in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/the-attribute-name-is-not-supported-on-an-instance/m-p/1061574#M61234</link>
    <description>&lt;P&gt;not all "layers" have the same properties.&amp;nbsp; It is a good idea to check for a particular layer type prior to checking any property unless you are sure it is common to all using the "is" methods.&amp;nbsp; For example&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;isFeatureLayer&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;should be used if you are checking for feature layers and they have a name&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&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;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The thing that brought this to my attention is the error message you got&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;'name' is not supported &lt;STRONG&gt;on this instance&lt;/STRONG&gt; of Layer.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;There are a number of different types of layers...&lt;/P&gt;</description>
    <pubDate>Tue, 25 May 2021 21:01:45 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2021-05-25T21:01:45Z</dc:date>
    <item>
      <title>The attribute 'name' is not supported on an instance of Layer</title>
      <link>https://community.esri.com/t5/python-questions/the-attribute-name-is-not-supported-on-an-instance/m-p/1061506#M61232</link>
      <description>&lt;P&gt;I'm trying to import a batch .mxds into ArcPro projects and have run into a NameError I can't figure out.&lt;/P&gt;&lt;P&gt;I need the script to walk some folders, import .mxds one at a time, remove some layers, add some layers, change some layers and then save a copy of each ArcPro project. Last week the script ran just fine in ArcPro 2.7. I updated to ArcPro 2.8 and the script was broken. I had IT do a clean reinstall of ArcPro but no joy.&lt;/P&gt;&lt;P&gt;The script is longish but it's a just a bunch of simple code strung together. The relevant part is:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject(r" path to blank .aprx ")
aprx.importDocument( .mxd path grabbed from folder walk )
            
            for m in aprx.listMaps():
                if m.name == "Layers":
                    print("Adding: {0}".format(addlyr))
                    print("Adding: {0}".format(addlyr2))
                    m.addDataFromPath(addlyr)
                    m.addDataFromPath(addlyr2)

                    for lyr in m.listLayers():

                        if lyr.name == "Graphics Layer":
                            m.removeLayer(lyr)&lt;/LI-CODE&gt;&lt;P&gt;I have a long string of elif statements after this one. It errors on this first one, but if I remove it the error triggers on the next one and so on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;This is the error message I get:&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\arcobjects\_base.py", line 90, in _get&lt;BR /&gt;return convertArcObjectToPythonObject(getattr(self._arc_object, attr_name))&lt;BR /&gt;AttributeError&lt;/P&gt;&lt;P&gt;During handling of the above exception, another exception occurred:&lt;/P&gt;&lt;P&gt;File: " my script " line 52, in &amp;lt;module&amp;gt;&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt;&lt;BR /&gt;if lyr.name == "Graphics Layer":&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\arcobjects\_base.py", line 96, in _get&lt;BR /&gt;(attr_name, self.__class__.__name__))&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;NameError: The attribute 'name' is not supported on this instance of Layer.&lt;/P&gt;&lt;P&gt;I've tried this in a separate script running from PyCharm and in an ArcPro notebook. Same error every time.&lt;/P&gt;&lt;P&gt;Has anybody else seen this?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 May 2021 18:48:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/the-attribute-name-is-not-supported-on-an-instance/m-p/1061506#M61232</guid>
      <dc:creator>Dailey_Don_L_</dc:creator>
      <dc:date>2021-05-25T18:48:07Z</dc:date>
    </item>
    <item>
      <title>Re: The attribute 'name' is not supported on an instance of Layer</title>
      <link>https://community.esri.com/t5/python-questions/the-attribute-name-is-not-supported-on-an-instance/m-p/1061540#M61233</link>
      <description>&lt;P&gt;It may just be a coincidence, and you have a layer which doesn't support the name property (I don't know which type of layer that would be though!).&lt;/P&gt;&lt;P&gt;Maybe to check this you could put in a try except&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;for lyr in m.listLayers():
    try:
        if lyr.name == "Graphics Layer":
        m.removeLayer(lyr)
        ...
    except:
        print(...)&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 25 May 2021 20:00:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/the-attribute-name-is-not-supported-on-an-instance/m-p/1061540#M61233</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-05-25T20:00:42Z</dc:date>
    </item>
    <item>
      <title>Re: The attribute 'name' is not supported on an instance of Layer</title>
      <link>https://community.esri.com/t5/python-questions/the-attribute-name-is-not-supported-on-an-instance/m-p/1061574#M61234</link>
      <description>&lt;P&gt;not all "layers" have the same properties.&amp;nbsp; It is a good idea to check for a particular layer type prior to checking any property unless you are sure it is common to all using the "is" methods.&amp;nbsp; For example&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;isFeatureLayer&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;should be used if you are checking for feature layers and they have a name&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&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;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The thing that brought this to my attention is the error message you got&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;'name' is not supported &lt;STRONG&gt;on this instance&lt;/STRONG&gt; of Layer.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;There are a number of different types of layers...&lt;/P&gt;</description>
      <pubDate>Tue, 25 May 2021 21:01:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/the-attribute-name-is-not-supported-on-an-instance/m-p/1061574#M61234</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-05-25T21:01:45Z</dc:date>
    </item>
    <item>
      <title>Re: The attribute 'name' is not supported on an instance of Layer</title>
      <link>https://community.esri.com/t5/python-questions/the-attribute-name-is-not-supported-on-an-instance/m-p/1065549#M61304</link>
      <description>&lt;P&gt;Just had the same thing went to Pro 2.8 and the layer.name property call is failing with this error, when it worked in 2.7.&lt;/P&gt;&lt;P&gt;Layer.name is a very common property to call and all Layers have historically supported this, it is there in the intellisense in the Python window, but if you try and access Layer.name you get this error &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;&lt;P&gt;so not a "you are calling a non-existent property issue", looks like a bug to me ..&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jun 2021 08:52:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/the-attribute-name-is-not-supported-on-an-instance/m-p/1065549#M61304</guid>
      <dc:creator>RobertHooley</dc:creator>
      <dc:date>2021-06-07T08:52:04Z</dc:date>
    </item>
    <item>
      <title>Re: The attribute 'name' is not supported on an instance of Layer</title>
      <link>https://community.esri.com/t5/python-questions/the-attribute-name-is-not-supported-on-an-instance/m-p/1065550#M61305</link>
      <description>&lt;P&gt;.. in fact this is happening on ALL layer properties not just name, rolling back to 2.7&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":crying_face:"&gt;😢&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;pro = arcpy.mp.ArcGISProject('CURRENT')&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;map = pro.activeMap&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;for lx in map.listLayers() :&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;if (lx.visible): pass&lt;/STRONG&gt;&lt;BR /&gt;&lt;FONT color="#993300"&gt;&lt;EM&gt;Traceback (most recent call last):&lt;/EM&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#993300"&gt;&lt;EM&gt;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\arcobjects\_base.py", line 90, in _get&lt;/EM&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#993300"&gt;&lt;EM&gt;return convertArcObjectToPythonObject(getattr(self._arc_object, attr_name))&lt;/EM&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#993300"&gt;&lt;EM&gt;AttributeError&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#993300"&gt;&lt;EM&gt;During handling of the above exception, another exception occurred:&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#993300"&gt;&lt;EM&gt;Traceback (most recent call last):&lt;/EM&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#993300"&gt;&lt;EM&gt;File "&amp;lt;string&amp;gt;", line 5, in &amp;lt;module&amp;gt;&lt;/EM&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#993300"&gt;&lt;EM&gt;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\arcobjects\_base.py", line 96, in _get&lt;/EM&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#993300"&gt;&lt;EM&gt;(attr_name, self.__class__.__name__))&lt;/EM&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#993300"&gt;&lt;EM&gt;NameError: The attribute 'visible' is not supported on this instance of Layer.&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jun 2021 09:03:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/the-attribute-name-is-not-supported-on-an-instance/m-p/1065550#M61305</guid>
      <dc:creator>RobertHooley</dc:creator>
      <dc:date>2021-06-07T09:03:30Z</dc:date>
    </item>
    <item>
      <title>Re: The attribute 'name' is not supported on an instance of Layer</title>
      <link>https://community.esri.com/t5/python-questions/the-attribute-name-is-not-supported-on-an-instance/m-p/1094996#M62236</link>
      <description>&lt;P&gt;I had this same issue. No need to downgrade to 2.7 as I believe this is intended behavior. I added the try except block that David Pike suggested and that fixed the issue. I guess not all layers have a name property. Seems weird but my tool is working again.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Update: I ended up changing it to&amp;nbsp;&lt;SPAN&gt;"if&amp;nbsp; lyr.supports("NAME"):" instead of the try/except because that seems like a better way to handle the situation.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Sep 2021 10:46:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/the-attribute-name-is-not-supported-on-an-instance/m-p/1094996#M62236</guid>
      <dc:creator>DavidShaeffer</dc:creator>
      <dc:date>2021-09-10T10:46:53Z</dc:date>
    </item>
    <item>
      <title>Re: The attribute 'name' is not supported on an instance of Layer</title>
      <link>https://community.esri.com/t5/python-questions/the-attribute-name-is-not-supported-on-an-instance/m-p/1095891#M62247</link>
      <description>&lt;P&gt;As a follow-up to this I eventually got the script to work by inserting "if&amp;nbsp; lyr.supports("NAME"):" which then allowed the script to run.&lt;/P&gt;&lt;P&gt;Like I mentioned above the original script failed even if I included only layers that I was certain supported the name property. I haven't had the opportunity to use the name property in a script in a different situation so I don't know if this was a one-off quirk. I do know that my original script ran exactly as I wanted before my upgrade to ArcPro 2.8.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Sep 2021 12:15:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/the-attribute-name-is-not-supported-on-an-instance/m-p/1095891#M62247</guid>
      <dc:creator>Dailey_Don_L_</dc:creator>
      <dc:date>2021-09-07T12:15:12Z</dc:date>
    </item>
  </channel>
</rss>

