I am trying to access the metadata for a map layer in ArcGIS Pro via arcpy. When I have a map layer, all of its properties from the Pro metadata tab of the layer properties are null. Here is a screenshot of my Python editor when I look at the map layer object in debug mode:
This is a layer that has its own metadata attached to the data source feature class. I copied the metadata to the layer, so it looks like the screenshot below, but I get the same result with null values.
If I go to the feature class (in a file geodatabase), I do get values:
>>> from arcpy import metadata as md >>> tgt_item_md = md.Metadata(fc_path) > tgt_item_md.isReadOnly False >>> tgt_item_md.title 'NOAA_WRC_Fish2015' >>> tgt_item_md.description '<DIV STYLE="text-align:Left;"><DIV><DIV><P><SPAN>The base geospatial information is the Watershed Boundary Dataset (WBD) [...etc...]'
Can anyone tell me how to correctly read the metadata from the layer properties metadata tab?
Solved! Go to Solution.
All I see is...
the last code example
Get a Metadata object from a map layer.
pulling out the properties as needed. So you can read from various start levels of info (project, map, layer) if you want.
I'm connecting to a Pro map layer that has metadata, but arcpy is returning all None values in the metadata properties. I'm not seeing how making a reusable def is going to help.
I thought the screenshot from my IDE would help, but it looks like it's a distraction. Here is what I am doing. This is a map layer that has metadata defined. Assume in_project (path to aprx), map_name, and map_layer_name are strings defined above.
aprx = arcpy.mp.ArcGISProject(in_project) map_out = aprx.listMaps(map_name) layers = map_out.listLayers() for layer in layers: if layer.name == map_layer_name: map_layer_out = layer map_layer_out <arcpy._mp.Layer object at 0x000001D64CFCFC50> layer_md = map_layer_out.metadata layer_md <arcpy.metadata.Metadata object at 0x000001D64CFC0438> layer_md.title # has no output type(layer_md.title) <class 'NoneType'> layer_md.description # has no output type(layer_md.description) <class 'NoneType'> type(layer_md.tags) <class 'NoneType'> type(layer_md.summary) <class 'NoneType'>
Shouldn't I be getting actual values there, like what I see in the Pro screenshot I posted?
Can you share a layer or layer package?
I tried several different scenarios, and all of them work as expected with metadata. I am using Pro 2.6.1, what version are you using?