Hello everyone,
I am not a developer, I'm using ArcGIS Pro 3.5.7. I am using ModelBuilder to run a scheduled model every 1st day of the month to export feature classes from a SQL geodatabase to a file geodatabase. The next script I would like to run after hours (every 1st of the month) is to update the summary section of the metadata of the feature classes in the file geodatabase with the current month and year and another 2 sentences added to the end of the current summary section.
I have asked my friend Google AI to tell me how to do this. It has failed. So I come to you, much smarter people. Here is what Google AI told me and I tried to run this in a ArcGIS Pro notebook.
from datetime import datetime
import arcpy
dataset_path = r"E:\ArcGIS Pro\Name.gdb\Name"
try:
# 1. Generate text snippet safely using built-in formatting
append_text = datetime.now().strftime(", %B %Y. Please note that")
# 2. Access the metadata object
target_metadata = arcpy.metadata.Metadata(dataset_path)
# 3. Safely read current summary using a rigid string conversion check
raw_summary = target_metadata.summary
# Check if raw_summary is a valid string, not a class type or None
if isinstance(raw_summary, str) and not isinstance(raw_summary, type):
current_summary = raw_summary
else:
current_summary = ""
# 4. Append and write back
target_metadata.summary = f"{current_summary}{append_text}"
# 5. Save changes
target_metadata.save()
print(f"Successfully updated metadata summary.")
except Exception as e:
print(f"Failed to update metadata: {e}")I get:
Failed to update metadata: <class 'type'> returned a result with an exception set
I have tried to find documentation on this and I searched the community for previous questions and answers but those are mostly very old so the software version is too old, and in some cases, they were using good old ArcMap. I did watch a few Esri videos about Metadata, very informative, but no mention of using python.
https://community.esri.com/t5/arcgis-pro-blog/live-training-seminar-metadata-essentials-for-ai/ba-p/1698657
https://mediaspace.esri.com/media/t/1_o8wuj2ba
https://doc.esri.com/en/arcgis-pro/latest/arcpy/metadata/what-is-the-metadata-module.html
Is this possible? Please help, thank you!
A