Layer.getExent() Crashes Arcmap

937
10
Jump to solution
07-04-2012 11:56 AM
MikeHunter
Occasional Contributor
The following code will crash a Python interpreter, or crash the entire Arcmap app if run inside the python window or in a toolbox tool:

import os, sys, time import arcpy  def main():          #make a layer from scratch     tfc = 'c:/arcview/sf/forest/tract.shp'     strmap = '4301'     t = 'tracts'     df = arcpy.AddFieldDelimiters(tfc, 'MAP')     exp = df + " = '" + strmap + "'"     result = arcpy.MakeFeatureLayer_management(tfc, t, exp)     lyr = result.getOutput(0)          # or get a layer from a .lyr file with the same def query     lyrfile = 'c:/temp/tract.lyr'      lyr2 = arcpy.mapping.Layer(lyrfile)           #either of the next 2 lines bombs python, or crashes Arcmap if inside app     ext = lyr.getExtent()     ext2 = lyr2.getExtent()  if __name__ == '__main__':     main() 


The problem is the definition query, since both layers work fine without it.  The query works, and GetCount returns 1 for each layer.  This is 10.1, XP SP3.  Any help would be appreciated.

thanks
Mike
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JeffBarrette
Esri Regular Contributor
This was fixed and will be made available with 10.1 SP1.

Jeff

View solution in original post

0 Kudos
10 Replies
JeffBarrette
Esri Regular Contributor
I can reproduce, I'll look into this.
Thanks,
Jeff
0 Kudos
MikeHunter
Occasional Contributor
Thank you sir.  Let us know if you figure something out.
Mike
0 Kudos
JeffBarrette
Esri Regular Contributor
This is a bug (NIM082523) and will be addressed for 10.1 SP1.  Arcpy is fetching a wrong (null) display transformation from layers generated from GP tools.

A possible work around it to reference the layers from within a Map Document.
1) Covert LYR to lyrfile, add to ArcMap TOC and reference it.
2) Use arcpy.mapping.ListLayers on the layer if it is automatically added to the TOC.

Thanks for reporting this,
Jeff
0 Kudos
JeffreySchmidt
New Contributor II
I have had a similar issue using .getSelectedExtent() in Python 2.7.  It restarts the shell whenever I use this method.  Glad to see it is going to be fixed.  Hopefully soon!
0 Kudos
JeffBarrette
Esri Regular Contributor
This was fixed and will be made available with 10.1 SP1.

Jeff
0 Kudos
Peter_von_Minden
New Contributor III
This was fixed and will be made available with 10.1 SP1.

Jeff


I have SP1 for 10.1 and I still get errors when using the layers getExtent() method on a layer with a definition query. The script hangs and dies unless I bypass all layers with a definition query in them.
0 Kudos
JeffBarrette
Esri Regular Contributor
I just tested this bug again using the original bug data and can NOT reproduce the problem using 10.1 SP1.

Its possible you have a different situation.  Please provide more details including part of your script.

Jeff
0 Kudos
Peter_von_Minden
New Contributor III
I just tested this bug again using the original bug data and can NOT reproduce the problem using 10.1 SP1. 

It's possible you have a different situation. Please provide more details including part of your script. 

Jeff


Hi Jeff,

This is the code I was testing on:

import arcpy

mxdFullPath = r"C:\temp\test_with_def.mxd"

mxd = arcpy.mapping.MapDocument(mxdFullPath)

for lyr in arcpy.mapping.ListLayers(mxd):
    if lyr.isFeatureLayer == True:
        print lyr.name
        LAYEREXTENT = lyr.getExtent()
        print str(LAYEREXTENT)


In my mxd (test_with_def.mxd) I have a series of definition queries. The above code seems to work for some of these layers with definition queries (eg: RDCLASS = 'National Highway' on a roads layer) but it falls over when it reaches a contours layer with this definition query:

mod(ELEVATION,100)=0

The error in PyScripter, when I reach the layer with this definition, is:

EOFError: [Errno 10054] An existing connection was forcibly closed by the remote host

All the layers are Oracle SDE layers.

Your thoughts on the matter would be most appreciated.

Cheers

Pete
0 Kudos
TomRutherford
New Contributor
I have SP1 for 10.1 and I still get errors when using the layers getExtent() method on a layer with a definition query. The script hangs and dies unless I bypass all layers with a definition query in them.


I also have 10.1 with SP1, and am getting a python crash on layer.getExtent()

Here's a simplified version of my code:

Layers = arcpy.mapping.ListLayers(arcpy.mapping.MapDocument(A_mxd_path))
for layer in Layers:
        print 'layer:', layer
        extent = layer.getExtent() #crash here after printing some layers


Here's the output I get up to the time python crashes:
layer strippedrx_poly_check 
layer shapefile 
layer strippedrx_poly_vr 
layer Yield1 
layer Yield2 
layer Yield3 
layer Yield4 
layer Yield5 
layer Borders 
layer VIEWS_2 
layer VIEWS_2\Image mosaic 
0 Kudos