Removing map from ArcGIS Pro project using ArcPy

4730
17
06-17-2017 01:53 AM
Status: Implemented
Labels (1)
GraemeBrowning
Occasional Contributor III

I have a desirable requirement to be able to remove a map from an ArcGIS Pro project using ArcPy.

However the ArcGISProject class does not seem to provide a method to do this.

I would like ArcPy to be enhanced to allow this.

My use case is a map automation application where I need to maintain three maps to support three MGA Zones (Australian "equivalent" to supporting three UTM Zones).  When the application exports a PDF at the end I also save a copy of the APRX so that the user wanting the PDF can, if need be, open up a copy of the project that created it (think of it as a draft), and perform some modifications before saving a final project/PDF.  Since each PDF only uses one of the MGA Zone maps I would like to unclutter the project before saving the copy by removing the other two MGA Zone maps.

Tags (3)
17 Comments
AmeliaBradshaw
Status changed to: Implemented

This Idea has been implemented in ArcGIS Pro 3.1. Please see the What's New documentation for more new features in Pro 3.1.

The Ideas in ArcGIS Pro 3.1 blog will be wrapped up soon. Once complete, I will add the link to this comment.

PaulDziemiela21

I rather think Amelie misread this enhancement and incorrectly marked the original request as implemented.

The original enhancement straightforwardly asks "I have a desirable requirement to be able to remove a map from an ArcGIS Pro project using ArcPy." - emphasis mine.

The provided 3.1 enhancement is in that vein of course, it provides a method to close all maps.  
See https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/arcgisproject-class.htm#M1_GUID-1117B216-CE8B...

However, Graeme is asking for a method to close one single map, not all of them.  So if a user has 100 maps open, we seek to close map #87 leaving the other 99 just as they are.  The aprx.closeViews() method does not address that need.

Could we thus reopen this enhancement?

It should also include a method to list the current open views as its difficult to know the items to close when one does not know what is open.  If this is not possible in future Pro iterations a note mentioning that would be helpful as well.

RichardHowe

@PaulDziemiela21 I don't think Amelia misread it at all. The original post was asking for a method to remove a map from a project.

The deleteItem (project_item) method, clearly provides for that and the post is correctly marked as implemented

 

What you are asking for may well be desirable functionality, but it is a new (and different) request from the original post and as such deserves its own post on the board

PaulDziemiela21

Hi Richard,

I suppose its about our interpretation of Graeme's requirement and what his verb, remove, means in the Pro catalog context.  I'll admit I was reading into things from this supporting stack exchange
https://gis.stackexchange.com/questions/463961/closing-single-map-view-in-arcgis-pro-using-arcpy

If the requirement and the solution is to delete (not close) individual maps, then I apologize and the requirement is met.

 

JeffBarrette

@PaulDziemiela21 , perhaps there is some understandable confusion with the term 'Map' - project item that defines a list of symbolized layers and a spatial reference like in the original statement "supporting three UTM Zones"  vs a 'MapView' - a window to display a Map where you can have one or many views displaying the same map, perhaps each with a different extents, for example.  

For managing a map project item, we have the ArcGISProject.deleteItem() method. I believe this addresses the original idea that we closed.  

If the discussion was intended to address closing MapView's then ...

MapViews do NOT have unique names so it is not currently possible in arcpy.mp to reference a specific MapView (e.g., 1 out of X) to close it.  The best, current solution is to reference the project item (map, layout, or report) and call openView().  This will open and activate the view.  If you don't want too many views open, there is also the option to call ArcGISProject.closeViews().  This allows you to do some clean up before opening a new map view.  There is a discussion about this in the same help topic listed above. It is very easy to close all views and then open the one or select few you want to see.  Also understand that these map views exist when the application is open.  If you are running Python scripts outside of the application, you can't work with views at all.

I completely understand your requirement but currently there is no way we can address it.

Jeff - Layout and arcpy.mp teams

uasdev
by

@RichardHowe Where is the deleteItem function in arcpy?

I do not see it when I search the ArcGIS Pro documentation.

I am a little confused, but the original question seemed like "How to remove map from ArcGIS Project using arcpy?" Was this functionality implemented?

JeffBarrette

@sadlkjiouasdf try ArcGISProject.deleteItem(project_item)

https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/arcgisproject-class.htm

 

Jeff - Layout SDK and arcpy.mp teams