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.
@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 viewOne 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 LayoutThe 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.
@JeffBarrette thanks for the response.
p.closeViews('LAYOUT', wildcard='My Layout')would be a suitable solution for my use case.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.