<?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: Not able to run python script outside of ArcMap in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/not-able-to-run-python-script-outside-of-arcmap/m-p/671383#M51993</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey Mike,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I just tested your code with some minor adjustments and its solid. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;One thing I would change is your output directory.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I ran this script using the PyScripter IDE.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's my snippet.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;One word of advice depending on the size of your grid feature, the time it takes to export to png could be lengthy.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
mxd = arcpy.mapping.MapDocument("D:\CommunityMaps\Brampton\Brampton\Map\CMdd_Brampton.mxd")
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
&amp;nbsp; mxd.dataDrivenPages.currentPageID = pageNum
&amp;nbsp; arcpy.mapping.ExportToPNG(mxd, r"D:\Results" + str(pageNum) + ".png")
del mxd
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you're running windows 7 you may need to create an environmental variable. See this thread for help:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://forums.arcgis.com/threads/13389-quot-No-module-named-os-quot-when-running-Python-Script-in-ArcGIS" rel="nofollow noopener noreferrer" target="_blank"&gt;http://forums.arcgis.com/threads/13389-quot-No-module-named-os-quot-when-running-Python-Script-in-ArcGIS&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Nelson&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 04:19:43 GMT</pubDate>
    <dc:creator>NelsonDe_Miranda</dc:creator>
    <dc:date>2021-12-12T04:19:43Z</dc:date>
    <item>
      <title>Not able to run python script outside of ArcMap</title>
      <link>https://community.esri.com/t5/python-questions/not-able-to-run-python-script-outside-of-arcmap/m-p/671381#M51991</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have been unable to get a python script that references a data driven pages mxd to run outside of ArcMap. This is a sample from the &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00sm00000008000000" rel="nofollow" target="_blank"&gt;ArcGIS Resource Center&lt;/A&gt;&lt;SPAN&gt; (bottom of the page) that I'm using as a base:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy mxd = arcpy.mapping.MapDocument("CURRENT") for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1): &amp;nbsp; mxd.dataDrivenPages.currentPageID = pageNum &amp;nbsp; arcpy.mapping.ExportToPNG(mxd, r"C:\Temp\ParcelAtlas_Page" + str(pageNum) + ".png") del mxd&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm attempting to modify the above code for my particular use (I do change the reference to a map document from "CURRENT" to an mxd on disk), but it won't run from a command line or an IDE (PyScripter); I don't get any errors, it's simply that nothing happens. Well, there's a pause for two to three seconds and then nothing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This runs fine from the python window in ArcMap. There must be something I haven't run across in my extensive searching on this issue, or it's so simple I'm overlooking it. What am I missing??&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I will disclose that I'm new-ish to python and programming in general, and I'm running ArcGIS 10 SP4 on Windows 7. Also, the map document that I'm referencing is over 8,000 pages. Not sure if that makes a difference, but thought I would mention it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Michael&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Aug 2012 19:22:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/not-able-to-run-python-script-outside-of-arcmap/m-p/671381#M51991</guid>
      <dc:creator>MichaelLinch</dc:creator>
      <dc:date>2012-08-02T19:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: Not able to run python script outside of ArcMap</title>
      <link>https://community.esri.com/t5/python-questions/not-able-to-run-python-script-outside-of-arcmap/m-p/671382#M51992</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Put some print statements in to check what it is doing, if it enters your loop with the expected arguments etc.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Aug 2012 19:40:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/not-able-to-run-python-script-outside-of-arcmap/m-p/671382#M51992</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2012-08-02T19:40:43Z</dc:date>
    </item>
    <item>
      <title>Re: Not able to run python script outside of ArcMap</title>
      <link>https://community.esri.com/t5/python-questions/not-able-to-run-python-script-outside-of-arcmap/m-p/671383#M51993</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey Mike,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I just tested your code with some minor adjustments and its solid. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;One thing I would change is your output directory.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I ran this script using the PyScripter IDE.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's my snippet.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;One word of advice depending on the size of your grid feature, the time it takes to export to png could be lengthy.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
mxd = arcpy.mapping.MapDocument("D:\CommunityMaps\Brampton\Brampton\Map\CMdd_Brampton.mxd")
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
&amp;nbsp; mxd.dataDrivenPages.currentPageID = pageNum
&amp;nbsp; arcpy.mapping.ExportToPNG(mxd, r"D:\Results" + str(pageNum) + ".png")
del mxd
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you're running windows 7 you may need to create an environmental variable. See this thread for help:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://forums.arcgis.com/threads/13389-quot-No-module-named-os-quot-when-running-Python-Script-in-ArcGIS" rel="nofollow noopener noreferrer" target="_blank"&gt;http://forums.arcgis.com/threads/13389-quot-No-module-named-os-quot-when-running-Python-Script-in-ArcGIS&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Nelson&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:19:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/not-able-to-run-python-script-outside-of-arcmap/m-p/671383#M51993</guid>
      <dc:creator>NelsonDe_Miranda</dc:creator>
      <dc:date>2021-12-12T04:19:43Z</dc:date>
    </item>
    <item>
      <title>Re: Not able to run python script outside of ArcMap</title>
      <link>https://community.esri.com/t5/python-questions/not-able-to-run-python-script-outside-of-arcmap/m-p/671384#M51994</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you for your responses.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It turns out it was something so simple I was overlooking it. I'm required to log in to an asset management solution that we have riding on top of ArcGIS. I'm so used to logging in that I never thought this could be what's preventing the script from running outside of ArcMap. I tried skipping the log in step when I open ArcMap and tried the code in the python window...it doesn't run.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'll be dealing with the log in portion of the script now, if I can even get that figured out.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Michael&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Aug 2012 21:33:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/not-able-to-run-python-script-outside-of-arcmap/m-p/671384#M51994</guid>
      <dc:creator>MichaelLinch</dc:creator>
      <dc:date>2012-08-02T21:33:48Z</dc:date>
    </item>
  </channel>
</rss>

