Select to view content in your preferred language

pythonw.exe crashing

1377
7
Jump to solution
04-30-2013 06:28 AM
MarcCusumano
Regular Contributor
I had some code working previously that is now causing pythonw.exe to crash. I have an .mxd set up that I am using to loop through features in a layer and export the layout to jpeg. However now the script crashes when it gets to df.zoomtoselectedfeatures. Here is what I have:

import arcpy  Path = os.getcwd() GSP_Join = "C:\\Users\\TDMC0\\AppData\\Local\\Temp\\scratch.gdb\\GSP_Join"  mxd = arcpy.mapping.MapDocument(Path + r"\GasLeaks2013.mxd") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] Layer = arcpy.mapping.ListLayers(mxd, "", df)[0] Layer2 = arcpy.mapping.ListLayers(mxd, "", df)[1] Layer3 = arcpy.mapping.ListLayers(mxd, "", df)[2]  # Create a search cursor try:      rows = arcpy.SearchCursor(GSP_Join, "", "", "CONN_OBJ_ID_NUM", "CONN_OBJ_ID_NUM")  except Exception as e:      print e  # Iterate through the Implausible Reads Feature, getting and zooming to respective extents and exporting layout to JPEG. currentState = " " count = arcpy.GetCount_management(GSP_Join) progress = 1  for row in rows:       try:                           if currentState != row.CONN_OBJ_ID_NUM:                print "\rExporting Data Driven Pages to JPEG...%s of %s" %(progress, count)                currentState = row.CONN_OBJ_ID_NUM                where_clause = "\"CONN_OBJ_ID_NUM\"=" + "'" + currentState + "'"                arcpy.SelectLayerByAttribute_management(Layer, "NEW_SELECTION",  where_clause)                df.zoomToSelectedFeatures()                df.scale = 5500                arcpy.RefreshActiveView()                arcpy.SelectLayerByAttribute_management (Layer, "CLEAR_SELECTION", "")                Layer.definitionQuery = where_clause                Layer2.definitionQuery = where_clause                Layer3.definitionQuery = where_clause                arcpy.mapping.ExportToJPEG(mxd, r"E:\GasLeaksProject\2012\JPEG\CONN_OBJ_ID_NUM" + str(currentState) + ".jpeg", resolution=300, jpeg_quality=70)                Layer.definitionQuery = ""                Layer2.definitionQuery = ""                Layer3.definitionQuery = ""                progress = progress + 1                      except Exception as e:           print e


When I run this I get a Windows OS message saying "pythonw.exe has crashed". I narrowed it down to the line df.zoomToSelectedFeatures() (if I comment out this line the code runs but obviously does not output what I want). Again this was working previously (about six months ago) I must have tested it a hundred times. All of the data sources are working in the mxd, and I tried re-saving the mxd and pointing to the new copy but no luck. I also printed my where_clause and it looks good. It must be a problem with my "list data frames / list layers code". Any help would be appreciated.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MarcCusumano
Regular Contributor
Solved this by creating an entirely new mxd. The original was not "corrupt" but there was something causing an issue. Thanks for the help.

View solution in original post

0 Kudos
7 Replies
MathewCoyle
Honored Contributor
Since you are going through a cursor anyway you can just get the extent of the row shape object instead of using a selection. Unless there is some particular reason you need to select it. I'm also assuming your selections are unique to each row since you call them CONN_OBJ_ID_NUM.
for row in cursor:
    df.extent = row.Shape.extent
0 Kudos
MarcCusumano
Regular Contributor
So pythonw.exe is still crashing, I don't think it has anything to do with what I previously thought. I I comment that out, it will get through 14 or so images and then crash. Can anyone see anything wrong with my code / how to optimize it? Thanks.
0 Kudos
MathewCoyle
Honored Contributor
If you watch the process and related threads does it get over 2GB? Do you have any AV program running?
0 Kudos
MarcCusumano
Regular Contributor
I found out that I cannot even pan to the features in the map document. The rest of the script - the part before the loop that exports the jpeg images - performs spatial selections and queries against point features to detect clusters of gas leaks and writes them to a gdb. The layers in the saved map document point to these new features. When I try to pan to the 24th record it crashes ArcMap.
0 Kudos
ChrisSnyder
Honored Contributor
Is there something wonkey with the 24th feature in your GSP_Join layer (null/corupt geometry)?

Can you do it manually and have it work correctly?
0 Kudos
MarcCusumano
Regular Contributor
I'm currently testing the process on separate machines - one running 10.0 and my main workstation running 10.1. I'll let you know what I find.
0 Kudos
MarcCusumano
Regular Contributor
Solved this by creating an entirely new mxd. The original was not "corrupt" but there was something causing an issue. Thanks for the help.
0 Kudos