<?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: Get workspace from layer object in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/get-workspace-from-layer-object/m-p/1233410#M66128</link>
    <description>&lt;P&gt;Apparently I was doing something wrong, but indeed the catalogPath from describe on the layer does allow the edit session to start. Thanks&amp;nbsp;@Anonymous User!&lt;/P&gt;&lt;P&gt;In my case, the data source of the layer is in a feature dataset, so here's the method I used to parse out the path to the sde connection file.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;catalogPath = arcpy.Describe(theLayer).catalogPath
# Traverse up the path to get the sde connection file or error at the end of the path.
while not catalogPath.endswith('.sde'):
    if catalogPath == os.path.dirname(catalogPath):
        raise OSError("This catalogPath does not have an sde connection file.")
    catalogPath = os.path.dirname(catalogPath)

with arcpy.da.Editor(catalogPath) as edit:
    # editing logic here&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 18 Nov 2022 21:17:05 GMT</pubDate>
    <dc:creator>BlakeTerhune</dc:creator>
    <dc:date>2022-11-18T21:17:05Z</dc:date>
    <item>
      <title>Get workspace from layer object</title>
      <link>https://community.esri.com/t5/python-questions/get-workspace-from-layer-object/m-p/1233037#M66104</link>
      <description>&lt;P&gt;I'm creating a Python toolbox in ArcGIS Pro that will start an &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/editor.htm" target="_self"&gt;edit session&lt;/A&gt;&amp;nbsp;on a layer in the map. In order to create the edit session, a workspace is needed. How can I derive the workspace from a layer in the map to use for the edit session? Nothing in &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/layer-class.htm" target="_self"&gt;Layer properties&lt;/A&gt; or &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/describe.htm" target="_self"&gt;Describe&lt;/A&gt; seems to work.&lt;/P&gt;&lt;P&gt;Since the layer is in an enterprise geodatabase (Oracle), the only solution I see right now is to get the connection_info from the layer object's&amp;nbsp;connectionProperties and create a new sde connection file in a temp folder. I'm hoping there's a better way.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 23:57:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-workspace-from-layer-object/m-p/1233037#M66104</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2022-11-17T23:57:08Z</dc:date>
    </item>
    <item>
      <title>Re: Get workspace from layer object</title>
      <link>https://community.esri.com/t5/python-questions/get-workspace-from-layer-object/m-p/1233047#M66105</link>
      <description>&lt;P&gt;Probably not the most elegant solution, but that is how I connect with my SDE. I just have a folder of all of them and use os.path.join(path_to_SDE_text_file, feature_class_name) in the init of the Tool class.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 23:51:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-workspace-from-layer-object/m-p/1233047#M66105</guid>
      <dc:creator>ccowin_odfw</dc:creator>
      <dc:date>2022-11-17T23:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: Get workspace from layer object</title>
      <link>https://community.esri.com/t5/python-questions/get-workspace-from-layer-object/m-p/1233179#M66110</link>
      <description>&lt;P&gt;I am testing branched version environment in an ArcPro 30 environment.&amp;nbsp; This is what I have been using to get a layers workspace from the layer's datasource. Essentially you grab everything from the layers datasource before the last "/" as the datasource also contains the feature class name.&amp;nbsp; &amp;nbsp;Not sure if it will work for you but seems to work for me.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;AnnoLayer = "Anno0200Scale" &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;thisProject = arcpy.mp.ArcGISProject("&lt;/SPAN&gt;&lt;SPAN&gt;CURRENT")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Map = thisProject.activeMap&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;AnnoLyr = Map.listLayers(AnnoLayer)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;FolderPath = thisProject.homeFolder&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;datasource = AnnoLyr.dataSource&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;lastslash = datasource.rfind("/")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;workspace = datasource[:lastslash]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.AddMessage(workspace)&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 13:44:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-workspace-from-layer-object/m-p/1233179#M66110</guid>
      <dc:creator>DeanAnderson2</dc:creator>
      <dc:date>2022-11-18T13:44:04Z</dc:date>
    </item>
    <item>
      <title>Re: Get workspace from layer object</title>
      <link>https://community.esri.com/t5/python-questions/get-workspace-from-layer-object/m-p/1233210#M66111</link>
      <description>&lt;P&gt;Hi Blake,&lt;/P&gt;&lt;P&gt;I'm wondering- did you try the arcpy.da.Describe() method?&amp;nbsp; It has catalogpath and path properties that you could use to parse out the path to the workspace.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;lyrDesc = arcpy.da.Describe(r'layer')
workspace = '\\'.join(lyrDesc["path"].split('\\')[:-1])&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 18 Nov 2022 15:47:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-workspace-from-layer-object/m-p/1233210#M66111</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-11-18T15:47:18Z</dc:date>
    </item>
    <item>
      <title>Re: Get workspace from layer object</title>
      <link>https://community.esri.com/t5/python-questions/get-workspace-from-layer-object/m-p/1233410#M66128</link>
      <description>&lt;P&gt;Apparently I was doing something wrong, but indeed the catalogPath from describe on the layer does allow the edit session to start. Thanks&amp;nbsp;@Anonymous User!&lt;/P&gt;&lt;P&gt;In my case, the data source of the layer is in a feature dataset, so here's the method I used to parse out the path to the sde connection file.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;catalogPath = arcpy.Describe(theLayer).catalogPath
# Traverse up the path to get the sde connection file or error at the end of the path.
while not catalogPath.endswith('.sde'):
    if catalogPath == os.path.dirname(catalogPath):
        raise OSError("This catalogPath does not have an sde connection file.")
    catalogPath = os.path.dirname(catalogPath)

with arcpy.da.Editor(catalogPath) as edit:
    # editing logic here&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 18 Nov 2022 21:17:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-workspace-from-layer-object/m-p/1233410#M66128</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2022-11-18T21:17:05Z</dc:date>
    </item>
  </channel>
</rss>

