Change active map with python in current project

05-13-2022 01:38 PM
New Contributor II

ArcGIS Pro 2.9.2 on Dell laptop running Windows 10.

I have a project opened and I want to use Python to change the active map. 

For this example, I have two maps in my ArcGISProject. Currently "Map A" is my active map, but when I run some geoprocessing tools, via python window, the output will be added to "Map A", but I want the output to be added to "B Map". 

Can I switch my active map with Python? Or how do I direct the output to a specific map? The arcpy.env does not seem to cover "maps".

import arcpy

aprx ='current')
map1 = aprx.listMaps("Map A")[0]
map2 = aprx.listMaps("B Map")[0]

Thanks for you help.


2 Replies
MVP Esteemed Contributor

Is the project open and you are using a notebook or the python window?

tool in arctoolbox

What circumstances would you need to add data to a map that isn't open instead of the one that is?

... sort of retired...
0 Kudos
New Contributor II
The project is open, and I am using the Python window.
Use case: In one map I generate a vector tile cache, in another map I process layers and tables for geocoding, routing and other purposes, and in a third map I add the vector tile package, routing network, and other layers and tables from "map2" and output a mobile map package.
Currently I have my scripts divided into 7 "steps" and I manually switch between windows and run the steps. Ideally, I'd like a single script to run the entire process.
I do understand the create vector tile cache and create mobile map package take the map name as an argument, so in theory I could have "map 2" as my active map. However, there is one function that is not exposed in python I must do manually in the vector tile cache "map" before running the create vector tile cache processing. And, I am still learning python to get the AOI layer at the bottom of the layer stack to create the mobile map package, or the extent of the mmpk is incorrect.
0 Kudos