ArcGIS Pro 2.8.3
The following lines seem to "technically" remove a layer from my map and save the project, but I still see the layer in the contents of my map until I close the project and re-open it. Do I need to refresh the contents somehow?
Thanks,
Solved! Go to Solution.
since you are running it from a tool, try
activeMap
see the 4th paragraph in
ArcGISProject—ArcGIS Pro | Documentation
More importantly, since you are using a tool, this reference provides some guidance on whether to reference the project on disk or if the project is open, to use CURRENT
Guidelines for arcpy.mp—ArcGIS Pro | Documentation
that may illuminate some differences, since changes to projects aren't persisted until projects are saved or saved to a copy
python window? python notebook? separate python IDE? tool in a toolbox?
and
There are many is properties that allow you to determine if a layer fits into a general category: is3DLayer, isFeatureLayer, isGroupLayer, isRasterLayer, and isServiceLayer
and remove is from layer files or the map class
LayerFile—ArcGIS Pro | Documentation
Map—ArcGIS Pro | Documentation
there is no refresh in arcgis pro's python
This is part of a script tool in a toolbox. The method I am using is removeLayer on the map class.
Here is a bit more of the code:
import sys, string, os, arcpy, time
from arcpy import env, mp
aprx = mp.ArcGISProject(aprxPath)
aprxMap = aprx.listMaps()[0]
for layer in aprxMap.listLayers():
if layer.name == 'myLayer':
aprxMap.removeLayer(layer)
aprx.save()
since you are running it from a tool, try
activeMap
see the 4th paragraph in
ArcGISProject—ArcGIS Pro | Documentation
More importantly, since you are using a tool, this reference provides some guidance on whether to reference the project on disk or if the project is open, to use CURRENT
Guidelines for arcpy.mp—ArcGIS Pro | Documentation
that may illuminate some differences, since changes to projects aren't persisted until projects are saved or saved to a copy
It just started working for me the way I had it written. Could be it was only not updating the layers when I was debugging in VSCode, but I could swear I had tested it from within AGPro as well. Thanks for your help!
it won't do anything in a separate python ide, it either has to be the python window, notebook or a toolbox script