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 = arcpy.mp.ArcGISProject('current')
map1 = aprx.listMaps("Map A")[0]
map2 = aprx.listMaps("B Map")[0]
Thanks for you help.
-John
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?
Did you ever figure out how to achieve the switch?
I also got stuck trying to do this with arcpy, currently looking into what SDK has to offer for this use case.
within the script I can target which map I add/remove/modify layers. This has help streamline the process. But I still have 3 scripts instead of 7. I still get tripped up in 2 places....
When I am processing layers and I want to add them to the map to output a mobile map package, I can specify the map to add the layers, and then I can turn them off as I don't want them visible, but usable by the app.
# --- gets the current ArcGIS Pro project file
aprx = arcpy.mp.ArcGISProject("CURRENT")
# --- gets the target map
m = aprx.listMaps("MMPK Output*")[0]
# --- sets the path and layers to add
LayerPath = ("D:\\Mobile Map Package Creator\\map_data.gdb\\")
LayerList = ("COMPLEXES", "MILEMARKERS", "Zones", "ROAD_NAMES")
# --- loops thru the layers and adds them to the target map, and then turns the visibility off
for Layer in LayerList:
AddStatus = m.addDataFromPath(LayerPath + Layer)
LayerName = m.listLayers(Layer)[0]
VisibleState = LayerName.visible = 0 #turn off layer
What trips me up?
The extent needs to be entered as a property of the map to create a vector tile cache, I can't find a way to do that in python.
I can't seem to use the above python to add a Network Dataset to the map.