Select to view content in your preferred language

arcpy.mp Map and Layout isOpen

241
2
4 weeks ago
Status: Needs Clarification
Labels (1)
Jeff-Reinhart
Frequent Contributor

For arcpy.mp Maps

arcpy.mp.ArcGISProject("CURRENT").listMaps()

and Layouts

arcpy.mp.ArcGISProject("CURRENT").listLayouts()

add an isOpen boolean property.

Use case:

layout = arcpy.mp.ArcGISProject("CURRENT").listLayouts('My Layout')[0]
if not layout.isOpen:
    layout.openView()

Without this, if the user runs the script multiple times, they get multiple views of the layout.

See also: https://community.esri.com/t5/python-questions/listing-open-maps-only-in-an-arcgis-pro-project/td-p/...

2 Comments
JeffBarrette
Status changed to: Needs Clarification

@Jeff-Reinhart thanks for your feedback!  I'd like to get additional feedback if possible.

First, anything that involves working with views via arcpy.mp, it is documented that these members only work for scripts that run within the application (in-process).  "Views" really don't exist when referencing a project by path (out-of-process).  Given that, we really try to limit the number of in-process only properties and methods.  Our main focus is automation and less application customization but we recognize the needs.

Second, currently we have ArcGISProject.closeViews() that takes an enum of project item types (i.e., maps, layouts, and reports).  So in your "My Layout" example you could have something like:

p = arcpy.mp.ArcGISProject("CURRENT")
lyt = p.listLayouts('My Layout')[0]
p.closeViews('LAYOUT')  #This closes all layout views
lyt.openView() #This opens AND activates your view

One of the limitations, in this example, is it closes all layout views, 'My Layout', 'Your Layout' 'Everybodys Layout' etc.  Probably more of an issue with Map items.

But what if we extended closeViews() to include a wildcard filter:

p.closeViews('LAYOUT', wildcard='My Layout') #This would close any views specific to My Layout

The above would close all instances of My Layout but then your would call openView to open AND activate it.

A possible problem with isOpen is the layout may be open but it might NOT be active.  That would require we add additional in-process only methods like .makeActive, which again, we would like to avoid.

Jeff-Reinhart

@JeffBarrette thanks for the response. 

p.closeViews('LAYOUT', wildcard='My Layout')

would be a suitable solution for my use case.