<?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 pass mxd as argument in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-pass-mxd-as-argument/m-p/125786#M9802</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I tend to forget and have to check which param by index I am actually fetching and of course it depends on how many variables you've set at the tool interface and in what order.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EDIT:&amp;nbsp; If you need a reference to the mxd object, then you have to pass the string into this statement (as it appears you were trying to do):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd = arcpy.mapping.MapDocument(r'your mxd pathname string')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In this case the mxd variable is an object reference whereas the initial GetParameterAsText mentioned was assigned to mxd as a string pathname (not an object).&amp;nbsp; So this sequence of commands may be a little more straightforward:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Get the string pathname (mxdStr), 1st param as a script tool&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxdStr = arcpy.GetParameterAsText(0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Pass the string to the MapDocument method to create the map doc object (mxdObj)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxdObj = arcpy.mapping.MapDocument(mxdStr)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 22 Dec 2012 23:47:57 GMT</pubDate>
    <dc:creator>T__WayneWhitley</dc:creator>
    <dc:date>2012-12-22T23:47:57Z</dc:date>
    <item>
      <title>How to pass mxd as argument</title>
      <link>https://community.esri.com/t5/python-questions/how-to-pass-mxd-as-argument/m-p/125784#M9800</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a simple script that is doing some parsing of the mxd that I pass it.&amp;nbsp; The script works just fine if I hard code the name of the mxd into the script, however I would like to pass the full path of the mxd to the script when I run it. This seems to be an issue since the examples I have seen all have the ???r??? in them prior to the path and mxd name.&amp;nbsp; For example(this works by the way):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;mxd = arcpy.mapping.MapDocument(r"C:\Data\GISData\PythonCode\test.mxd")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I???ve tried a number of things but haven???t figured out how to get around this simple problem.&amp;nbsp; For Example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;mxdIn = sys.argv[0] mxd = arcpy.mapping.MapDocument(mxdIn)&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Also tried:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;mxdIn = sys.argv[0] mxd = arcpy.mapping.MapDocument(r (mxdIn))&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your help in advance!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 22 Dec 2012 20:49:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-pass-mxd-as-argument/m-p/125784#M9800</guid>
      <dc:creator>FrankRoberts</dc:creator>
      <dc:date>2012-12-22T20:49:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass mxd as argument</title>
      <link>https://community.esri.com/t5/python-questions/how-to-pass-mxd-as-argument/m-p/125785#M9801</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try mxd = arcpy.GetParameterAsText(1) passing in your mxd document name.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EDIT:&amp;nbsp; Actually, it is arcpy.GetParameterAsText(0) to fetch the 1st parameter set at your script tool's interface.&amp;nbsp; What threw me is that you were using sys.argv[0], which I think should be sys.argv[1].&amp;nbsp; It has been a while since I have fetched parameters the 'system argument' route, which is still valid, however, if not mistaken, sys.argv[0] fetches the script name.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, this should work, doing it your way (provided of course that the argument is a valid mxd pathname):&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;mxdIn = sys.argv[1] mxd = arcpy.mapping.MapDocument(mxdIn)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 22 Dec 2012 23:39:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-pass-mxd-as-argument/m-p/125785#M9801</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2012-12-22T23:39:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass mxd as argument</title>
      <link>https://community.esri.com/t5/python-questions/how-to-pass-mxd-as-argument/m-p/125786#M9802</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I tend to forget and have to check which param by index I am actually fetching and of course it depends on how many variables you've set at the tool interface and in what order.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EDIT:&amp;nbsp; If you need a reference to the mxd object, then you have to pass the string into this statement (as it appears you were trying to do):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd = arcpy.mapping.MapDocument(r'your mxd pathname string')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In this case the mxd variable is an object reference whereas the initial GetParameterAsText mentioned was assigned to mxd as a string pathname (not an object).&amp;nbsp; So this sequence of commands may be a little more straightforward:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Get the string pathname (mxdStr), 1st param as a script tool&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxdStr = arcpy.GetParameterAsText(0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Pass the string to the MapDocument method to create the map doc object (mxdObj)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxdObj = arcpy.mapping.MapDocument(mxdStr)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 22 Dec 2012 23:47:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-pass-mxd-as-argument/m-p/125786#M9802</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2012-12-22T23:47:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass mxd as argument</title>
      <link>https://community.esri.com/t5/python-questions/how-to-pass-mxd-as-argument/m-p/125787#M9803</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Wayne that was it!&amp;nbsp; I knew it had to be something simple:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So this was my solution:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
mxdIn = arcpy.GetParameterAsText(0)
mxd = arcpy.mapping.MapDocument(mxdIn)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Have a great Christmas!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:09:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-pass-mxd-as-argument/m-p/125787#M9803</guid>
      <dc:creator>FrankRoberts</dc:creator>
      <dc:date>2021-12-11T07:09:37Z</dc:date>
    </item>
  </channel>
</rss>

