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()
Solved! Go to Solution.
This was fixed and will be made available with 10.1 SP1.
Jeff
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
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)
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.
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
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