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

279
4
07-06-2020 03:14 PM
KarimD
by
New Contributor II

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,

4 Replies
DanPatterson
MVP Honored 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
New Contributor II

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 Honored 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
New Contributor II

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