<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: pro 2.4 layer data source in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/pro-2-4-layer-data-source/m-p/215300#M16607</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In case anyone else has this question - although there's been radio silence for the last 7 months so probably not.... &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is my solution.&amp;nbsp; There is probably a better way...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Currently I have to have my script work in both ArcPro 2.3.3 and ArcPro 2.4.3.&amp;nbsp; 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....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;layers = activeMap.listLayers()&lt;/P&gt;&lt;P&gt;for lyr in layers:&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;if lyr.isBasemapLayer == False and lyr.isGroupLayer == False:&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if lyr.dataSource.split(',')[0].split('=')[0] == "Server":&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dataset = lyr.dataSource.split(',')[-1].split('=')[1]&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else:&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dataset = lyr.dataSource&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Bit of a rigmarole when it was working perfectly fine before but at least I have something going now!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 03 Feb 2020 02:57:11 GMT</pubDate>
    <dc:creator>MicheleH1_DNReply</dc:creator>
    <dc:date>2020-02-03T02:57:11Z</dc:date>
    <item>
      <title>pro 2.4 layer data source</title>
      <link>https://community.esri.com/t5/python-questions/pro-2-4-layer-data-source/m-p/215299#M16606</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a script was working fine in ArcGIS Pro 2.3.3.&amp;nbsp; I am looping through all the layers in a map looking for a specific layer.&amp;nbsp; 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.&lt;/P&gt;&lt;P&gt;The code below is what I have.&amp;nbsp; This line:&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 13px;"&gt;if os.path.basename(lyr.dataSource) == planSummaryLayer&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;is now returning:&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 13px;"&gt;Server=brcsvgissql01,Instance=test,Database Platform=SQL Server,Version=dbo.DEFAULT,Authentication Type=Operating System Authentication,Dataset=test.DBO.EP_PlanSummary_v8&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;rather than just:&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 13px;"&gt;test.DBO.EP_PlanSummary_v8&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;as it was with ArcGIS Pro 2.3.3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;How do I now just get the basename of the data source from the layer in a map?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I'm not too great with python so please let me know if you need any more information.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks for your help.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;import sys, string, os, arcpy&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;aprx = arcpy.mp.ArcGISProject('CURRENT')&lt;BR /&gt;activeMap = aprx.activeMap&lt;/P&gt;&lt;P&gt;planSummaryLayer = 'test.DBO.EP_PlanSummary_v8'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;layers = activeMap.listLayers()&lt;BR /&gt;for lyr in layers:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if lyr.isBasemapLayer == False and lyr.isGroupLayer == False:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if os.path.basename(lyr.dataSource) == planSummaryLayer:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; desc = arcpy.Describe(lyr)&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jul 2019 02:02:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pro-2-4-layer-data-source/m-p/215299#M16606</guid>
      <dc:creator>MicheleH1_DNReply</dc:creator>
      <dc:date>2019-07-03T02:02:12Z</dc:date>
    </item>
    <item>
      <title>Re: pro 2.4 layer data source</title>
      <link>https://community.esri.com/t5/python-questions/pro-2-4-layer-data-source/m-p/215300#M16607</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In case anyone else has this question - although there's been radio silence for the last 7 months so probably not.... &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is my solution.&amp;nbsp; There is probably a better way...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Currently I have to have my script work in both ArcPro 2.3.3 and ArcPro 2.4.3.&amp;nbsp; 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....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;layers = activeMap.listLayers()&lt;/P&gt;&lt;P&gt;for lyr in layers:&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;if lyr.isBasemapLayer == False and lyr.isGroupLayer == False:&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if lyr.dataSource.split(',')[0].split('=')[0] == "Server":&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dataset = lyr.dataSource.split(',')[-1].split('=')[1]&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else:&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dataset = lyr.dataSource&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Bit of a rigmarole when it was working perfectly fine before but at least I have something going now!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Feb 2020 02:57:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pro-2-4-layer-data-source/m-p/215300#M16607</guid>
      <dc:creator>MicheleH1_DNReply</dc:creator>
      <dc:date>2020-02-03T02:57:11Z</dc:date>
    </item>
  </channel>
</rss>

