Select to view content in your preferred language

Change metadata of my map using a custom script tool in ArcGIS Pro

2290
6
07-06-2020 03:14 PM
KarimD
by
Emerging Contributor

Hello everybody,

I got a question about updating metadata in ArcGIS pro using a custom script tool (arcpy metadata module).

Specifically, I want to update metadata of my map using a custom script tool, and here is my problem :

1-The metadata of the map is read only when I use the script tool.

In my script, if I launch the following command :

      aprx = arcpy.mp.ArcGISProject("CURRENT")

      current_map = aprx.listMaps("Map")[0]

      map_metadata = current_map.metadata

      arcpy.AddMessage (str(map_metadata.isReadOnly))

      output : True

It appears that the map metadata is read only.

2-What’s even weirder is that if I launch the same command from the Python window of ArcGIS PRO, the map metadata is not read only :

      aprx = arcpy.mp.ArcGISProject("CURRENT")

      current_map = aprx.listMaps("Map")[0]

      map_metadata = current_map.metadata

      print (str(map_metadata.isReadOnly))

      output : False

It appears that the map metadata is not read only.

 

How can I update my metadata using a toolbox ? Ideally, I want to make the map metadata as not read only.

Thanks,

6 Replies
DanPatterson
MVP Esteemed Contributor

Metadata—Metadata module | Documentation 

import arcpy
aprx = arcpy.mp.ArcGISProject("CURRENT")
current_map = aprx.activeMap
map_metadata = current_map.metadata
print(map_metadata.title)
print(map_metadata.description)‍‍‍‍‍‍

whether python window or otherwise, the example gets the map specified whether it is an active map or  from a list of maps called "Map"

In your case, may be you need

current_map = aprx.listMaps("Map")[0]

map_metadata = current_map.metadata

print (str(map_metadata.isReadOnly))


... sort of retired...
0 Kudos
KarimD
by
Emerging Contributor

Hi Dan Patterson,


Thank you for your reply.


« whether python window or otherwise » : well...in my machine, getting the map metadatas through the python window enables me to edit the map metadatas. Whereas getting the map metadatas through my custom script tool prevents me from editing the map metadatas.


Here are my theories:

  • There is some option I am not aware of that enables editing map metadatas when using a custom script tool (basically arcpy);
  • There is a bug in ArcGIS Pro, and I need to submit it. The bug is that, during scripting, the map metadatas are not readonly when using the python window, but they become readonly when using a custom script tool.

I point to the fact that I need to change the map metadatas (not the layers, not the layout, not the feature classes...). The way you do that for each component seems to be very specific. What seems to be working for the feature layers is not necessarily working for the map.

Please let me know if you know how to change the map metadatas using a custom script tool ?

Thanks,

0 Kudos
DanPatterson
MVP Esteemed Contributor

You can check the current list of publicly listed bugs here.

https://support.esri.com/en/Search-Results#search?q=map%20metadata%20arcgis%20pro&content-type=Bugs

If you think it is a bug, then you can file a case with Tech Support, or if you think there is a need for clarification in the help documentation, you can report it on the help page for the page you are using.


... sort of retired...
0 Kudos
KarimD
by
Emerging Contributor

Hi Dan Patterson‌,

There was a mistake in my original question (it has been edited). I obviously got the the map metadata object before printing it 

Still, my problem remains: why does the value of the "isReadOnly" attribute is different depending on whether I use the Python window or the custom script tool ?

Thanks,

0 Kudos
JosephMcGehan
Occasional Contributor

I have the same issue. I'm making a task tool, driven by py tools. The metadata object remains read only. I can make my own metadata object and populate it, but can't copy and save it in the map metadata object. The Map Metadata object remains read only. This happens when using a script tool in ArcGIS Pro, or when running py via idle with ArcGIS Pro closed.

 

m = aprx.activeMap
m.name = Title  #set the map elements name to the same as the title
# create empty metadata object and populate it with our varibles
new_md = md.Metadata()
new_md.title = 'Title'
new_md.tags = 'Tag1, Tag2'
new_md.summary = 'Summary'
new_md.description = 'Description'
new_md.credits = 'My Credits'
activemap_metadata = md.Metadata(m) #the metadata object for the active map
if activemap_metadata.isReadOnly:
    arcpy.AddMessage("the metadata object for the active map is read only")
else:
    activemap_metadata.copy(new_md)
    activemap_metadata.save()

 

0 Kudos
JosephMcGehan
Occasional Contributor

Solved:

 

        m.name = ShortTitle
        map_metadata = m.metadata
        map_metadata.title = Title
        map_metadata.summary = Summary       
        map_metadata.description = Description
        map_metadata.tags = Tag
        map_metadata.credits = Credits
        map_metadata.accessConstraints = Terms
        map_metadata.save()