In this article you will learn how to turn on a layer in several MXD files using Python.
It may happen that during the execution of a project in which you have been making different graphical outputs and/or maps that for some reason you turned off a layer used to represent certain spatial information (Shapefile, feature Class, among others) and now it turns out that its visualization is necessary. The traditional solution could be one of the following:
How to turn on an ArcGIS / ArcMap layer?
Option 1:
1) Open the MXD file.
2) Click on the checkbox (a) of the layer to turn on (box to the left of the layer), which activates the checklist sign (b).
3) Save the MXD file.
4) Repeat the procedure for each MXD file.
Option 2:
1) Open the MXD file.
2) Click on the layer to be activated so that it is shaded, once the layer is selected press the space bar (a), which activates the checklist sign (b).
3) Save the MXD file.
4) Repeat the procedure for each MXD file.
Option 3: (Switch on several layers without a consecutive order)
1) Open the MXD file.
2) Click on the layers to be activated while holding down the Ctrl key, once all layers are selected press the space bar (a), which turns on the checklist sign (b).
3) Save the MXD file.
4) Repeat the procedure for each MXD file.
Option 4: (Turn on several layers in consecutive order)
1) Open the MXD file.
2) Click on the first of the layers to turn on (a) while holding down the Shitf key and press the last of the layers (b), once all layers are selected press the space bar, which activates the checklist sign (c). It works even if the order of layer selection is reversed during steps (a) and (b).
3) Save the MXD file.
4) Repeat the procedure for each MXD file.
In case the correction must be done to one or two files it is not a big deal, but if the correction must be done on dozens of images and/or maps in MXD format this can consume a lot of your time, next, I will show you how it can be much more efficient using Python code (Don't worry you don't need to know how to program to do it).
How to batch turn off layers in multiple ArcGIS / ArcMap files using Python?
Step 1: Open a blank MXD file.
Step 2: Open the Python window in the Standard toolbar.
Step 3: Backup the original MXD files.
Step 4: Copy the following code into a notepad and in line #05 of the code replace the path C:\EJEMPLO\EJEMPLO with the path where the MXD files to be modified are stored.
Step 5: In line #11 of the code replace LAYER with the name of the layer to turn on.
Step 6: Copy the modified code into the Python window and press the Enter key twice.
After a few seconds you will see how the modification date of the ArcMap files starts to update, and when you open it you will notice that the display of the layer in each MXD file has been activated.
I hope you enjoyed this article, soon I will upload a video explaining the procedure that you can consult in this blog, as well as another article where I will explain how to add layers within a particular layer group. Save my blog among your favorite links, I will be uploading many more tricks of this style, remember that you can send me your questions in the contact page or leave your comment, I will be attentive to respond.





