By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,814 Members | 1,050 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,814 IT Pros & Developers. It's quick & easy.

Automating capture of Extent from multiple mxds with multiple dataframes

P: 1
Hi,

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 python script to do this (code below) 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 - an Attribute Error is generated.

I also want it to write the scale and title of the frame as well as the file name of the mxd in to the extents shape file.

Would appreciate your help in completing this script.

Thanks,

George


Expand|Select|Wrap|Line Numbers
  1. import arcpy, os, glob
  2. path = 'P:\\2011\\Job_031_TownPlanning_SeriesProduction\\Working\\mxd\\1'
  3. os.chdir(path)
  4. mxds_List = glob.glob('*.mxd')
  5. mxd2 = glob.glob('*.shp')
  6. count_Mapdocs = len(mxds_List)
  7. print 'Processing ' + str(count_Mapdocs) + 'map documents...'
  8. #Create Polygon Shapefile
  9. arcpy.CreateFeatureclass_management(path, 'extents.shp', "POLYGON")
  10. arcpy.CreateFeatureclass_management(path, 'mxds.shp', "POLYGON")
  11. #Start Loop
  12. for mxd2 in mxds_List:
  13.     mapDoc = arcpy.mapping.MapDocument(mxd)
  14.     dataframe = arcpy.mapping.ListDataFrames(mapDoc,'*')[0]
  15.     frameExtent = dataframe.extent
  16.     #Frame Scale
  17.     frameScale = dataframe.scale
  18.     #Frame Extent
  19.     ExtentXMax = frameExtent.XMax
  20.     ExtentXMin  = frameExtent.XMin
  21.     ExtentYXax  = frameExtent.YMax
  22.     ExtentYMin  = frameExtent.YMin
  23.     point_object = mxd2.shp
  24.     #Write in table scale
  25.     #Write in table
  26.  
--- OUTPUT START

Processing 14map documents... Traceback (most recent call last): File "P:\2011\Job_031_TownPlanning_SeriesProduction\Wor king\extent.py", line 31, in point_object = mxd2.shp AttributeError: 'str' object has no attribute 'shp'

--- END OUTPUT
May 5 '11 #1
Share this Question
Share on Google+
2 Replies


bvdet
Expert Mod 2.5K+
P: 2,851
I noticed one problem. On line 5 you make the assignment mxd2 = glob.glob('*.shp') and on line 12 you again use the identifier mxd2 in the for loop.
May 5 '11 #2

P: 5
Here is some sample code that I was able to get working. You will need to create an array and add the XMAX, XMIN, etc to the array to create the polygon feature. Then you can create a feature class/shapefile from this array. I had trouble getting the Append tool to work with the array feature so I created a feature class for each extent, merged them together, and then deleted the original extent feature classes.

Expand|Select|Wrap|Line Numbers
  1. import arcpy, glob, os
  2. from arcpy import env
  3. from arcpy import mapping
  4. env.overwriteOutput = True
  5.  
  6. path = r"C:\temp"
  7. mxdList = glob.glob(path + "\*.mxd")
  8.  
  9. env.workspace = r"C:\temp\Test.gdb"
  10.  
  11. y = 1
  12.  
  13. for mxd in mxdList:
  14.     mxd2 = mapping.MapDocument(mxd)
  15.     dataframe = mapping.ListDataFrames(mxd2, "*")[0]
  16.     frameExtent = dataframe.extent
  17.     XMAX = frameExtent.XMax
  18.     XMIN = frameExtent.XMin
  19.     YMAX = frameExtent.YMax
  20.     YMIN = frameExtent.YMin
  21.     pnt1 = arcpy.Point(XMIN, YMIN)
  22.     pnt2 = arcpy.Point(XMIN, YMAX)
  23.     pnt3 = arcpy.Point(XMAX, YMAX)
  24.     pnt4 = arcpy.Point(XMAX, YMIN)
  25.     array = arcpy.Array()
  26.     array.add(pnt1)
  27.     array.add(pnt2)
  28.     array.add(pnt3)
  29.     array.add(pnt4)
  30.     array.add(pnt1)
  31.     polygon = arcpy.Polygon(array)
  32.     arcpy.CopyFeatures_management(polygon, "Polygon_Extent" + "_" + str(y))
  33.     y = y + 1
  34.  
  35.  
  36. list = []
  37.  
  38. lstFCs = arcpy.ListFeatureClasses("Polygon_Extent*")
  39. for fc in lstFCs:
  40.     list.append(fc)
  41.  
  42. arcpy.Merge_management(list, "Extent")
  43.  
  44. for item in list:
  45.     arcpy.Delete_management(item)
  46.  
May 5 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.