Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

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 want to create a single shape file from multiple mxd's that have multiple frame sets with different extents in them. I have found/started a script to do this (attached) but can't figure out how to write the captured X&Y Max/Min into the shape file that is created for this. See output below. I also want it to write the scale and title of the frame as well as the file name of the mxd.

Can you help complete this script?

 import arcpy, glob, os from arcpy
 import env from arcpy import mapping
 env.overwriteOutput = True

 path = r"C:\temp" mxdList =
 glob.glob(path + "\*.mxd")

 env.workspace = r"C:\temp\Test.gdb"

 y = 1

 for mxd in mxdList:
     mxd2 = mapping.MapDocument(mxd)
     dataframe = mapping.ListDataFrames(mxd2, "*")[0]
     frameExtent = dataframe.extent
     XMAX = frameExtent.XMax
     XMIN = frameExtent.XMin
     YMAX = frameExtent.YMax
     YMIN = frameExtent.YMin
     pnt1 = arcpy.Point(XMIN, YMIN)
     pnt2 = arcpy.Point(XMIN, YMAX)
     pnt3 = arcpy.Point(XMAX, YMAX)
     pnt4 = arcpy.Point(XMAX, YMIN)
     array = arcpy.Array()
     polygon = arcpy.Polygon(array)
 "Polygon_Extent" + "_" + str(y))
     y = y + 1

 list = []

 lstFCs =
 for fc in lstFCs:

 arcpy.Merge_management(list, "Extent")

 for item in list:

Even with this I get errors...

Traceback (most recent call last):
  File "P:\2011\Job_031_TownPlanning_SeriesProduction\Working\mxd\", line 32, in <module>
    arcpy.CopyFeatures_management(polygon, "Polygon_Extent" + "_" + str(y))
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\", line 1943, in CopyFeatures
    raise e
ExecuteError: ERROR 000210: Cannot create output Polygon_Extent_1
Failed to execute (CopyFeatures).
share|improve this question

Since you specify you are using shapefiles, you'll need to add shp to the output.

Change this line

    arcpy.CopyFeatures_management(polygon, "Polygon_Extent" + "_" + str(y))

To this

    arcpy.CopyFeatures_management(polygon, "Polygon_Extent" + "_" + str(y) + ".shp")

Also, change this line

    arcpy.Merge_management(list, "Extent")

To this

    arcpy.Merge_management(list, "Extent.shp")
share|improve this answer
Thanks...I made these changes and now get the following. ... – GeorgeC May 10 '11 at 4:06
npeihl, thanks for your input. I now get – GeorgeC May 10 '11 at 4:10

npeihl, Thanks for your input...I now get.

P:\2011\Job_031_TownPlanning_SeriesProduction\Working\mxd\1 219157.947938379 8072842.27839025 377350.947938381 8205437.27839025 NaN NaN NaN NaN 377350.947938 219157.947938 8205437.27839 8072842.27839 219157.947938379 8072842.27839025 NaN NaN 219157.947938379 8205437.27839025 NaN NaN 377350.947938381 8205437.27839025 NaN NaN 377350.947938381 8072842.27839025 NaN NaN Traceback (most recent call last): File "C:\Python26\ArcGIS10.0\Lib\site-packages\Pythonwin\pywin\framework\", line 322, in RunScript, main._dict_, start_stepping=0) File "C:\Python26\ArcGIS10.0\Lib\site-packages\Pythonwin\pywin\", line 60, in run _GetCurrentDebugger().run(cmd, globals,locals, start_stepping) File "C:\Python26\ArcGIS10.0\Lib\site-packages\Pythonwin\pywin\debugger\", line 655, in run exec cmd in globals, locals File "P:\2011\Job_031_TownPlanning_SeriesProduction\Working\mxd\1\", line 40, in TempFile = open(polygon, "Polygon_Extent" + "_" + str(y)) # open file TypeError: coercing to Unicode: need string or buffer, Polygon found

share|improve this answer
up vote 0 down vote accepted

Thanks all, the code has been (fixed) and the basic functionality is working. I am still trying to get it to write the mxd file name, extent name and scale but the extent->polygon shp file works when run using IDLE in the same directory as the mxd's.

Would still appreciate help with the above though - I have posted a new question for this at How do I insert a DATAFRAME_ELEMENT value into a dynamically generated shape file containing its extent?

(working) CODE in link above.

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.