Select to view content in your preferred language

pro 2.4 layer data source

850
1
Jump to solution
07-02-2019 07:02 PM
MicheleH1_DNReply
Deactivated User

I have a script was working fine in ArcGIS Pro 2.3.3.  I am looping through all the layers in a map looking for a specific layer.  I am matching on the data source (specifically os.path.basename(lyr.dataSource)). I don't want to look for what the layer is called in the map as this needs to run for multiple people in different projects and people may rename the layer to anything.

The code below is what I have.  This line:

if os.path.basename(lyr.dataSource) == planSummaryLayer

is now returning:

Server=brcsvgissql01,Instance=test,Database Platform=SQL Server,Version=dbo.DEFAULT,Authentication Type=Operating System Authentication,Dataset=test.DBO.EP_PlanSummary_v8

rather than just:

test.DBO.EP_PlanSummary_v8

as it was with ArcGIS Pro 2.3.3

How do I now just get the basename of the data source from the layer in a map?

I'm not too great with python so please let me know if you need any more information.

Thanks for your help.

import sys, string, os, arcpy

aprx = arcpy.mp.ArcGISProject('CURRENT')
activeMap = aprx.activeMap

planSummaryLayer = 'test.DBO.EP_PlanSummary_v8'

layers = activeMap.listLayers()
for lyr in layers:
    if lyr.isBasemapLayer == False and lyr.isGroupLayer == False:
        if os.path.basename(lyr.dataSource) == planSummaryLayer:

            desc = arcpy.Describe(lyr)

0 Kudos
1 Solution

Accepted Solutions
MicheleH1_DNReply
Deactivated User

In case anyone else has this question - although there's been radio silence for the last 7 months so probably not....  

Here is my solution.  There is probably a better way...

Currently I have to have my script work in both ArcPro 2.3.3 and ArcPro 2.4.3.  I couldn't quickly work out how to get the version of ArcPro in python so I decided to check the result of lyr.dataSource instead....

layers = activeMap.listLayers()

for lyr in layers:
   if lyr.isBasemapLayer == False and lyr.isGroupLayer == False:
      if lyr.dataSource.split(',')[0].split('=')[0] == "Server":
         dataset = lyr.dataSource.split(',')[-1].split('=')[1]
      else:
         dataset = lyr.dataSource

Bit of a rigmarole when it was working perfectly fine before but at least I have something going now!

View solution in original post

0 Kudos
1 Reply
MicheleH1_DNReply
Deactivated User

In case anyone else has this question - although there's been radio silence for the last 7 months so probably not....  

Here is my solution.  There is probably a better way...

Currently I have to have my script work in both ArcPro 2.3.3 and ArcPro 2.4.3.  I couldn't quickly work out how to get the version of ArcPro in python so I decided to check the result of lyr.dataSource instead....

layers = activeMap.listLayers()

for lyr in layers:
   if lyr.isBasemapLayer == False and lyr.isGroupLayer == False:
      if lyr.dataSource.split(',')[0].split('=')[0] == "Server":
         dataset = lyr.dataSource.split(',')[-1].split('=')[1]
      else:
         dataset = lyr.dataSource

Bit of a rigmarole when it was working perfectly fine before but at least I have something going now!

0 Kudos