Apply Changes to Mapview

1050
3
Jump to solution
02-11-2021 01:22 PM
ChrisHolmes
Occasional Contributor III

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

 

 

0 Kudos
1 Solution

Accepted Solutions
MatthewDriscoll
MVP Alum

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

 

The application always refreshes when using CURRENT

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."

 

 

View solution in original post

3 Replies
MatthewDriscoll
MVP Alum

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

 

The application always refreshes when using CURRENT

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."

 

 

ChrisHolmes
Occasional Contributor III

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. 🙂

ChrisHolmes
Occasional Contributor III

ChrisHolmes_0-1613495899099.png

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()?

0 Kudos