<?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: How to get workspace path for map in Pro in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-get-workspace-path-for-map-in-pro/m-p/1254575#M66782</link>
    <description>&lt;P&gt;That is my observation as well. It seems ArcGIS Pro makes some kind of temporary copy of the connection file while the app is open. However, I've been able to do everything I need with this connection file (short of knowing where the original sde file is).&lt;/P&gt;</description>
    <pubDate>Thu, 02 Feb 2023 20:39:36 GMT</pubDate>
    <dc:creator>BlakeTerhune</dc:creator>
    <dc:date>2023-02-02T20:39:36Z</dc:date>
    <item>
      <title>How to get workspace path for map in Pro</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-workspace-path-for-map-in-pro/m-p/1254492#M66774</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Where in arcpy for ArcGIS Pro can you obtain the workspaces from the map or layers? I cannot find this property in documentation? Specially I am looking for the name and path of the SDE connection file. This&amp;nbsp;was very helpful when resourcing maps as we use standardize SDE connection names so we migrate maps to other environments we easily find and replace the workspace connection locations&amp;nbsp; &amp;amp; names.&amp;nbsp;&lt;/P&gt;&lt;P&gt;In arcpy.mapping for layers in MXDs there is a property which returns the workspacePaths for the layer. The reference is below.&lt;/P&gt;&lt;P&gt;&lt;A href="https://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-mapping/layer-class.htm" target="_blank" rel="noopener"&gt;https://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-mapping/layer-class.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;In the ArcGIS Pro this help has an example of using the&amp;nbsp;&lt;SPAN&gt;updateConnectionProperties method. For Enterprise Geodatabases, how does one obtain this connection string so this can be achieved?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/updatingandfixingdatasources.htm" target="_blank" rel="noopener"&gt;https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/updatingandfixingdatasources.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RonnieRichards_0-1675363383332.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/61983i4FBE732E5C66801F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RonnieRichards_0-1675363383332.png" alt="RonnieRichards_0-1675363383332.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;There is an info tip in the Layer help stating there is no reference to the .sde connection file.&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/layer-class.htm" target="_blank" rel="noopener"&gt;https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/layer-class.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;Tip:
Enterprise geodatabase layers in an ArcGIS Pro project
do not retain the path to the database connection file (.sde) 
that was used to create the layer.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Without the original workspacePath/connection string how is it possible to read the .SDE connections from the map and update them programmatically using&amp;nbsp;&lt;SPAN&gt;updateConnectionProperties?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2023 19:00:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-workspace-path-for-map-in-pro/m-p/1254492#M66774</guid>
      <dc:creator>RonnieRichards</dc:creator>
      <dc:date>2023-02-02T19:00:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to get workspace path for map in Pro</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-workspace-path-for-map-in-pro/m-p/1254508#M66775</link>
      <description>&lt;P&gt;I used &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/describe.htm" target="_self"&gt;Describe&lt;/A&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os

def getWorkspaceInfo(map_layer):
    """Takes an input map layer object and returns a dictionary with workspace information.
    """
    try:
        # Get workspace of input map layer
        workspace_path = arcpy.Describe(map_layer).catalogPath
        # Walk up the catalogPath until it's at the connection file.
        while not workspace_path.endswith('.sde'):
            if workspace_path == os.path.dirname(workspace_path):
                # You've reached the end (beginning) of the path.
                raise OSError("This catalogPath does not have an sde connection file.")
            workspace_path = os.path.dirname(workspace_path)
        workspace_desc = arcpy.Describe(workspace_path)
        workspace_instance = workspace_desc.connectionProperties.instance
        workspace_version = workspace_desc.connectionProperties.version
        # Get only the portion of the instance after the last colon character.
        # This might not be necessary depending on your rdbms.
        workspace_instance = workspace_instance.rsplit(":", 1)[1]
        if workspace_instance and workspace_version:
            return {
                "workspace_path": workspace_path,
                "workspace_instance": workspace_instance,
                "workspace_version": workspace_version
            }
        else:
            # workspace_instance or workspace_version is missing.
            raise AttributeError(f"workspace_instance is {workspace_instance}; workspace_version is {workspace_version}")
    except Exception as e:
        raise arcpy.ExecuteError(
            f"Unable to get workspace instance and version from map_layer {map_layer.name}"
        ) from e


# Get workspace path to .sde file
workspace_info = getWorkspaceInfo(my_map_layer_obj)
workspace_path = workspace_info["workspace_path"]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2023 18:58:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-workspace-path-for-map-in-pro/m-p/1254508#M66775</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2023-02-02T18:58:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to get workspace path for map in Pro</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-workspace-path-for-map-in-pro/m-p/1254511#M66777</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;A href="https://community.esri.com/t5/user/viewprofilepage/user-id/191789" target="_blank"&gt;@BlakeTerhune&lt;/A&gt;&amp;nbsp;that was very quick and this is perfect!&lt;/P&gt;&lt;P&gt;I'll have to test but does describe work on broken data sources as well?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2023 19:02:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-workspace-path-for-map-in-pro/m-p/1254511#M66777</guid>
      <dc:creator>RonnieRichards</dc:creator>
      <dc:date>2023-02-02T19:02:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to get workspace path for map in Pro</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-workspace-path-for-map-in-pro/m-p/1254512#M66778</link>
      <description>&lt;P&gt;I haven't tested it with broken data sources. I'm not sure how it would handle that.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2023 19:02:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-workspace-path-for-map-in-pro/m-p/1254512#M66778</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2023-02-02T19:02:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to get workspace path for map in Pro</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-workspace-path-for-map-in-pro/m-p/1254521#M66779</link>
      <description>&lt;P&gt;For some reason this Describe catalog path does not return the original SDE Connection used. The map document was authored using a UNC path with standardized names and a temporary .sde connection was returned. Does it return the expected .sde connection file name and path in your situation?&lt;/P&gt;&lt;P&gt;The map was authored with data from: \\servername\publish\readuser@prodDB_web_sde.sde\web_sde.GIS.COUNTY_BOUNDARY&lt;/P&gt;&lt;P&gt;The describe returns: C:\Users\username\AppData\Local\Temp\1\a2190f00b0450b088ca7cd2e92f9f4b5.sde\web_sde.GIS.COUNTY_BOUNDARY&lt;/P&gt;&lt;P&gt;This might be what that little tip was indicating in the layer help but this is not at all helpful if the sde connections are always in the local profile with the orignal naming destroyed.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2023 19:25:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-workspace-path-for-map-in-pro/m-p/1254521#M66779</guid>
      <dc:creator>RonnieRichards</dc:creator>
      <dc:date>2023-02-02T19:25:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to get workspace path for map in Pro</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-workspace-path-for-map-in-pro/m-p/1254575#M66782</link>
      <description>&lt;P&gt;That is my observation as well. It seems ArcGIS Pro makes some kind of temporary copy of the connection file while the app is open. However, I've been able to do everything I need with this connection file (short of knowing where the original sde file is).&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2023 20:39:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-workspace-path-for-map-in-pro/m-p/1254575#M66782</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2023-02-02T20:39:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to get workspace path for map in Pro</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-workspace-path-for-map-in-pro/m-p/1254910#M66794</link>
      <description>&lt;P&gt;Thanks for the confirmation&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/191789"&gt;@BlakeTerhune&lt;/a&gt;&amp;nbsp;! Your solution is perfect to obtain a path to a .sde workspace. ArcGIS Pro seems to copy or create the sde connection into the local profile. It's unfortunate the original path was not preserved but maybe this was removed due to security or other issues if source connections are exposed.&amp;nbsp;&lt;/P&gt;&lt;P&gt;On this end, we will proceed with resourcing data on what exists in the connection properties. Thanks for your response to this&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2023 16:50:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-workspace-path-for-map-in-pro/m-p/1254910#M66794</guid>
      <dc:creator>RonnieRichards</dc:creator>
      <dc:date>2023-02-03T16:50:24Z</dc:date>
    </item>
  </channel>
</rss>

