Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a script which selects an extent from a grid and exports the data frame.

import os, arcpy

mxd = arcpy.mapping.MapDocument('CURRENT')
df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
grid_lyr = arcpy.mapping.ListLayers(mxd,"grid")[0]
scur = arcpy.SearchCursor(grid_lyr)

for row in scur:
    sqlExp = """{0} = '{1}'""".format(arcpy.AddFieldDelimiters(grid_lyr,"PageName"),row.getValue("PageName"))
    print "Selecting {}".format(row.getValue("PageName"))
    df.extent = grid_lyr.getSelectedExtent(False)
    df.scale = df.scale*1.05
    arcpy.mapping.ExportToTIFF(mxd,os.path.join(r'C:\temp\109147',row.getValue("PageName")+".tif"),df,817, 534,world_file=True)

del scur, mxd

I ran this script last week, and it crashed ArcMap after exporting the first tiff. I then ran it in a blank ArcMap document, changed CURRENT to the full path and it worked (all 414 tiff files exported).

I am running the same script again today, on the same data, from a blank document. It now successfully exports the first two tiffs, and then stops executing as if it is finished, without any errors. When I try to run it again, ArcMap crashes again. I am not sure what the problem is, last week when it failed I just opened a blank document, as that normally solves the issues half the time.

I updated the code to include print statements for debugging:

for row in scur:
    print "Row count: " +str(arcpy.GetCount_management(grid_lyr))
    sqlExp = """{0} = '{1}'""".format(arcpy.AddFieldDelimiters(grid_lyr,"PageName"),row.getValue("PageName"))
    print "SQL is: {}".format(sqlExp)
    df.extent = grid_lyr.getSelectedExtent(False)
    df.scale = df.scale*1.05
    print "Data frame {0} has a scale of {1}".format(, df.scale)
    name = os.path.join(r'C:\temp\109147',row.getValue("PageName")+".tif")
    arcpy.mapping.ExportToTIFF(mxd,name,df,817, 534,world_file=True)
    print "Exported {}".format(name) 

del scur, mxd, row

The output was:

Row count: 500
SQL is: "PageName" = 'E3'
Data frame Layers has a scale of 2276.80888604
Exported C:\temp\109147\E3.tif
Row count: 1
SQL is: "PageName" = 'E4'
Data frame Layers has a scale of 2276.80888604
Exported C:\temp\109147\E4.tif

My grid layer only has 414 features, so the row count numbers are a bit weird. Also, if I try to define the cursor variable again in the same session, ArcMap crashes.

share|improve this question
Are you deleting your search cursor and row objects? – artwork21 May 6 '13 at 14:43
Yes I am, forgot to add in the last line. – Cindy Williams-Jayakumar May 6 '13 at 18:29
What about the row object (del row)? – artwork21 May 6 '13 at 18:35
Have you checked to make sure that no records are selected in grid_lyr when you start the script? If anything is selected when you get going ONLY those records will show up in the cursor. – Kevin May 6 '13 at 18:43
@artwork21 I've checked and realised I did not have that in my script, although it ran fine without it last week. I'll add in del row now and check if it works. – Cindy Williams-Jayakumar May 7 '13 at 4:51

I had a similar behaviour which I found out has to do with the arcpy.mapping site package. Since its the newest part in arcpy and is implemented as a wrapper for ArcObjects, it has problems in its error handling capabilities. Calls to arcpy.mapping may crash very often. And also if you try to catch exceptions, that does not work, because exceptions are never thrown. It simply kills the python interpreter. I told this to the ESRI support and they accepted it as a Bug (NIM090073). Hopefully it will be fixed with the next ServicePack.

You can easily check if this also happens here if you uncomment the Line

arcpy.mapping.ExportToTIFF(mxd,name,df,817, 534,world_file=True)

The cursor loop should finish then. Also you can check with a python debugger if the script crashes on the above line.

As a workaround our ESRI distributor told us to install ArcGIS 10.1 SP1 for Desktop Background Geoprocessing (64-Bit) from here . Of course you need ArcGIS 10.1 with Service Pack 1 installed and you need a 64-Bit machine, but that helped so my arcpy.mapping script ran through without problems.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.