Hello,
I have the following procedure which turns layers on or off on a mapview. But I find that the changes only apply if I save the project but I find saving the project adds alot of time onto the execution of the script. Is there something different I can do, possibly some way that will just update the mapview where the layers have been turned on/off?
Thanks!
def SetLayers(prj, mapName, lyrs, status):
aprx = arcpy.mp.ArcGISProject(prj)
m = aprx.listMaps(mapName)[0]
for lyr in m.listLayers():
if lyr.name.upper() in lyrs:
if status == 'on':
lyr.visible = True
else:
lyr.visible = False
aprx.save()
del aprx
Solved! Go to Solution.
Unfortunately they took away the refreshActiveView option in pro. If possible use CURRENT for the map.
https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/migratingfrom10xarcpymapping.htm
When you use the CURRENT keyword in the Python window with ArcGIS Desktop, you sometimes had to call refreshActiveView to force a screen refresh. This is no longer the case with ArcGIS Pro. All arcpy.mp API changes directly update ArcGIS Pro."
Unfortunately they took away the refreshActiveView option in pro. If possible use CURRENT for the map.
https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/migratingfrom10xarcpymapping.htm
When you use the CURRENT keyword in the Python window with ArcGIS Desktop, you sometimes had to call refreshActiveView to force a screen refresh. This is no longer the case with ArcGIS Pro. All arcpy.mp API changes directly update ArcGIS Pro."
That is completely correct and actually I remember reading this link in the past. SetLayers is used to turn layers on/off before running a procedure to create images. As a test I ran it how it currently works (using a passed in path to a project), I set it to create 4 images but killed the script after 12 minutes and having created 2 of the images.
I then changed my code to use 'CURRENT', reran the test and it created all 4 images in 35 seconds!
Thanks for the reminder. 🙂
I'm assuming though if there is a need to save the project at the end of a script that works with 'CURRENT', you will still need to do a .save()?