AttributeError: 'Layer' object has no attribute 'metadata' from ArcPy with ArcGIS Pro
I think you are trying to use a property that only became available in versions later than ArcGIS Pro 2.4.
When I run the code below:
import arcpy aprx = arcpy.mp.ArcGISProject(r"C:\temp\Projects\TestProject\TestProject.aprx") mapx = aprx.listMaps() print(mapx.name) lyr = mapx.listLayers() print(lyr.name) print(lyr.metadata.description)
Python 3.6.10 |Anaconda, Inc.| (default, May 20 2020, 01:49:13) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license()" for more information. >>> ========================== RESTART: C:\temp\test.py ========================== Map TestPoly None >>>
In this instance I am not sure why
metadata.description is reporting as
None because I have given that layer (and its underlying feature class) what I believe are valid values. In any event, my version (which is later than ArcGIS Pro 2.4) does recognise the
metadata property of the layer which your version 2.4 does not.
When I run this code in the Python window of the same project I do see the expected output:
aprx = arcpy.mp.ArcGISProject("CURRENT") layer = aprx.listMaps().listLayers() layer_metadata = layer.metadata print(layer_metadata.title) print(layer_metadata.description) TestPoly <DIV STYLE="text-align:Left;"><DIV><DIV><P><SPAN STYLE="font-size:12pt">This is my test description that I added from the Catalog pane by right-clicking on the feature class and choosing Edit Metadata. I then copied the metadata from the feature class to a layer created from it using the Metadata tab of the Layer Properties.</SPAN></P></DIV></DIV></DIV>
I reported the above to Esri, and they said:
It is currently a known issue and the metadata team is working on a fix.