<?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: Read MXD path in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/read-mxd-path/m-p/405527#M31905</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Do you mean the path to where the MXD is or a path to where the data associated with the MXD is.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you mean where the data associated with the MXD is.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Start ArcCatalog.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Navigate to where your MXD is.&amp;nbsp; Right Click on it and select Set Data Sources. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Or inside or an ArcGIS session In the table of contents there should be a button to list by source.&amp;nbsp; And it will show you all the sources. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hy Guys,&lt;BR /&gt;&lt;BR /&gt;I'm new in python and I would like to know if there is a way to read the MXD path (e.g C:\temp\arquivo.mxd) ?&lt;BR /&gt;&lt;BR /&gt;I have to create a MXD, then open it and add some layers, I tried this:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy, os

mxd = file("template1.mxd", "a")
mxd.close()
mxd1 = arcpy.mapping.MapDocument(mxd)
df = arcpy.mapping.ListDataFrames(mxd1, "Dados")[0]
addLayer = arcpy.mapping.Layer(r"D:\Eduardo\Dados_teste\Temp\sanepar\TemplateFlags.lyr")
arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")
mxd1.save()
del mxd1, addLayer
&lt;/PRE&gt;&lt;BR /&gt;It works if the MXD is previously created but I'd like to create a blank MXD.&amp;nbsp; I don't know how to pass the mxd full path to arcpy.mapping.MapDocument.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Eduardo&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 18:26:39 GMT</pubDate>
    <dc:creator>RobertBorchert</dc:creator>
    <dc:date>2021-12-11T18:26:39Z</dc:date>
    <item>
      <title>Read MXD path</title>
      <link>https://community.esri.com/t5/python-questions/read-mxd-path/m-p/405526#M31904</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hy Guys,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm new in python and I would like to know if there is a way to read the MXD path (e.g C:\temp\arquivo.mxd) ?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have to create a MXD, then open it and add some layers, I tried this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
import arcpy, os

mxd = file("template1.mxd", "a")
mxd.close()
mxd1 = arcpy.mapping.MapDocument(mxd)
df = arcpy.mapping.ListDataFrames(mxd1, "Dados")[0]
addLayer = arcpy.mapping.Layer(r"D:\Eduardo\Dados_teste\Temp\sanepar\TemplateFlags.lyr")
arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")
mxd1.save()
del mxd1, addLayer
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN&gt;It works if the MXD is previously created but I'd like to create a blank MXD.&amp;nbsp; I don't know how to pass the mxd full path to arcpy.mapping.MapDocument.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Eduardo&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Apr 2013 14:20:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/read-mxd-path/m-p/405526#M31904</guid>
      <dc:creator>EduardoCamargo_de_Araujo</dc:creator>
      <dc:date>2013-04-12T14:20:11Z</dc:date>
    </item>
    <item>
      <title>Re: Read MXD path</title>
      <link>https://community.esri.com/t5/python-questions/read-mxd-path/m-p/405527#M31905</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Do you mean the path to where the MXD is or a path to where the data associated with the MXD is.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you mean where the data associated with the MXD is.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Start ArcCatalog.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Navigate to where your MXD is.&amp;nbsp; Right Click on it and select Set Data Sources. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Or inside or an ArcGIS session In the table of contents there should be a button to list by source.&amp;nbsp; And it will show you all the sources. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hy Guys,&lt;BR /&gt;&lt;BR /&gt;I'm new in python and I would like to know if there is a way to read the MXD path (e.g C:\temp\arquivo.mxd) ?&lt;BR /&gt;&lt;BR /&gt;I have to create a MXD, then open it and add some layers, I tried this:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy, os

mxd = file("template1.mxd", "a")
mxd.close()
mxd1 = arcpy.mapping.MapDocument(mxd)
df = arcpy.mapping.ListDataFrames(mxd1, "Dados")[0]
addLayer = arcpy.mapping.Layer(r"D:\Eduardo\Dados_teste\Temp\sanepar\TemplateFlags.lyr")
arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")
mxd1.save()
del mxd1, addLayer
&lt;/PRE&gt;&lt;BR /&gt;It works if the MXD is previously created but I'd like to create a blank MXD.&amp;nbsp; I don't know how to pass the mxd full path to arcpy.mapping.MapDocument.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Eduardo&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:26:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/read-mxd-path/m-p/405527#M31905</guid>
      <dc:creator>RobertBorchert</dc:creator>
      <dc:date>2021-12-11T18:26:39Z</dc:date>
    </item>
    <item>
      <title>Re: Read MXD path</title>
      <link>https://community.esri.com/t5/python-questions/read-mxd-path/m-p/405528#M31906</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Robert,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;but I would like to know Where the MXD is (e.g C:\temp\test.mxd) !&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Using the ArcMap interface I know how to get this. I would like to do this through python.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Apr 2013 14:36:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/read-mxd-path/m-p/405528#M31906</guid>
      <dc:creator>EduardoCamargo_de_Araujo</dc:creator>
      <dc:date>2013-04-12T14:36:18Z</dc:date>
    </item>
    <item>
      <title>Re: Read MXD path</title>
      <link>https://community.esri.com/t5/python-questions/read-mxd-path/m-p/405529#M31907</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If you want to read the filePath property of the MapDocument, you can do this:&lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
print mxd.filePath&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, from your previous thread, it sounds like you also might want to create a new blank mxd in your script. This is not possible. The arcpy.mapping module was designed so that it can be used to modify existing elements within already existing map documents. In other words, it helps with the automation of existing features but it can't be used to author new objects. It is possible to make changes to existing map documents and then save the changes out to a new file using the saveACopy method on the MapDocument or Layer objects. It also possible to author and save a blank mxd in the UI, and then reference it with arcpy.mapping.MapDocument.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:26:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/read-mxd-path/m-p/405529#M31907</guid>
      <dc:creator>JeffMoulds</dc:creator>
      <dc:date>2021-12-11T18:26:41Z</dc:date>
    </item>
  </channel>
</rss>

