Select to view content in your preferred language

Not able to run python script outside of ArcMap

3498
3
Jump to solution
08-02-2012 12:22 PM
MichaelLinch
Deactivated User
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 ArcGIS Resource Center (bottom of the page) that I'm using as a base:

import arcpy mxd = arcpy.mapping.MapDocument("CURRENT") for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):   mxd.dataDrivenPages.currentPageID = pageNum   arcpy.mapping.ExportToPNG(mxd, r"C:\Temp\ParcelAtlas_Page" + str(pageNum) + ".png") del mxd


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.

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??

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.

Thank you,

Michael
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MichaelLinch
Deactivated User
Thank you for your responses.

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.

I'll be dealing with the log in portion of the script now, if I can even get that figured out.

Michael

View solution in original post

0 Kudos
3 Replies
MathewCoyle
Honored Contributor
Put some print statements in to check what it is doing, if it enters your loop with the expected arguments etc.
0 Kudos
NelsonDe_Miranda
Frequent Contributor
Hey Mike,

I just tested your code with some minor adjustments and its solid.
One thing I would change is your output directory.

I ran this script using the PyScripter IDE.
Here's my snippet.

One word of advice depending on the size of your grid feature, the time it takes to export to png could be lengthy.

import arcpy
mxd = arcpy.mapping.MapDocument("D:\CommunityMaps\Brampton\Brampton\Map\CMdd_Brampton.mxd")
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
  mxd.dataDrivenPages.currentPageID = pageNum
  arcpy.mapping.ExportToPNG(mxd, r"D:\Results" + str(pageNum) + ".png")
del mxd


If you're running windows 7 you may need to create an environmental variable. See this thread for help:
http://forums.arcgis.com/threads/13389-quot-No-module-named-os-quot-when-running-Python-Script-in-Ar...

Cheers,

Nelson
0 Kudos
MichaelLinch
Deactivated User
Thank you for your responses.

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.

I'll be dealing with the log in portion of the script now, if I can even get that figured out.

Michael
0 Kudos