Select to view content in your preferred language

arcpy Describe lyrx data source

573
1
12-21-2023 07:32 AM
mj_gis
by
Occasional Contributor

Hi All,

I have a relatively simple script that describes the data source and folder for lyrx files. The script worked fine in ArcMap but I am reformatting it for Pro and can't get the same output as the Arcmap script had. The script works if the lyrx is being sourced from a geodatabase or an arcgis server service. However, if the data is being sourced from an enterprise geodatabase, it gives me a temporary directory, based on whichever user is running the script. Any ideas how I can get the entire SDE path instead of the location of the temporary connection? 

Example output-- Layer data source: C:\Users\myuser\AppData\Local\Temp\1\3c5684340c6099e99efde564bfbadb12.sde\sdedatabasename.feasturedataset\sdedatabase.featureclassname


for file in files:
test = arcpy.Describe(file)
if test.layer.dataType == 'FeatureLayer':
arcpy.AddMessage("Working on " + file)
path = '{}\{}'.format(inDir, file) # Adding the inDir path to the front of the file name
desc = arcpy.Describe(path)
print("Layer data source: {}".format(desc.layer.catalogPath))
print ("Folder path to LYRX file: {}".format(desc.path))
 


 





 

0 Kudos
1 Reply
AlfredBaldenweck
MVP Regular Contributor

Not sure what was supposed to be in those other boxes, but this worked fine for me (a little slow, though)

import arcpy
import os
for root, dirs, files in os.walk(r"T:\WY\HDD\RL\_layerfiles\cadastral"):
    for file in files:
        # print(file)
        if file.endswith((".lyr", ".lyrx")):
            lyrx = arcpy.mp.LayerFile(os.path.join(root,file))
            for layer in lyrx.listLayers():
                if layer.isGroupLayer:
                    continue
                if layer.isBasemapLayer:
                    continue
                print(arcpy.da.Describe(layer)["catalogPath"])

 

On your last line, btw, you could probably just do  

 print ("Folder path to LYRX file: {}".format(path))

 

0 Kudos