Change Data Source of .lyrx files in bulk and permanently.

Jump to solution
03-16-2021 12:15 PM
Labels (3)
New Contributor III

I was given a bulk batch of lyr files that were converted to lyrx files with paths to a file gdb that is no longer in operation. All of the feature classes I would like to redirect the the lyrx files to are on an Enterprise GDB which connects through an sde connection file housed on a networked server. 

Any time I add a lyrx file to a map and change its data source, it only holds for that particular project. It also sets the source to a local drive temp path, even though I set its connection to the sde connection file. Is there any method to permanently change the data source of a lyrx file in bulk like in ArcCatalog, or through some python script? 

This seems like a major ESRI oversight. Thanks for the help! 

0 Kudos
11 Replies
Regular Contributor

Hi Derek,

The thing is that your content is located on fileshare. We need to amend a bit your paths, therefore.

Also, it is better to create new files, instead of overwriting existinig ones. Simply, in case of a failure, these files may get corrupted.

Please check the following code. Hopefully, it works for you.

import arcpy
import os

filesDirectory = r"\\\\svgcisilon.path\\gis\\Mitigation"
fileExt = r".lyrx"
files = [os.path.join(filesDirectory, f) for f in os.listdir(filesDirectory) if f.endswith(fileExt)] 
for file in files:
     lyrFile =
     lyrFile.updateConnectionProperties(r"\\\\svgcisilon.path\\gis\\MitigationLayers\\MitigationBanks.gdb", r"\\\\svgcisilon.path\\gis\\envi@sv03.sde")
lyrFile.saveACopy(file.split(".lyrx")[0] + "SDE.lyrx")




View solution in original post

0 Kudos
New Contributor III

Awesome! This is perfect 🙂 Thanks for the help. 

0 Kudos