Automating capture of Extent from multiple mxds with multiple dataframes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • George Corea
    New Member
    • May 2011
    • 1

    Automating capture of Extent from multiple mxds with multiple dataframes

    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


    Code:
    import arcpy, os, glob
    path = 'P:\\2011\\Job_031_TownPlanning_SeriesProduction\\Working\\mxd\\1'
    os.chdir(path)
    mxds_List = glob.glob('*.mxd')
    mxd2 = glob.glob('*.shp')
    count_Mapdocs = len(mxds_List)
    print 'Processing ' + str(count_Mapdocs) + 'map documents...'
    #Create Polygon Shapefile
    arcpy.CreateFeatureclass_management(path, 'extents.shp', "POLYGON")
    arcpy.CreateFeatureclass_management(path, 'mxds.shp', "POLYGON")
    #Start Loop
    for mxd2 in mxds_List:
        mapDoc = arcpy.mapping.MapDocument(mxd)
        dataframe = arcpy.mapping.ListDataFrames(mapDoc,'*')[0]
        frameExtent = dataframe.extent
        #Frame Scale
        frameScale = dataframe.scale
        #Frame Extent
        ExtentXMax = frameExtent.XMax
        ExtentXMin  = frameExtent.XMin
        ExtentYXax  = frameExtent.YMax
        ExtentYMin  = frameExtent.YMin
        point_object = mxd2.shp
        #Write in table scale
        #Write in table
    --- OUTPUT START

    Processing 14map documents... Traceback (most recent call last): File "P:\2011\Job_03 1_TownPlanning_ SeriesProductio n\Working\exten t.py", line 31, in point_object = mxd2.shp AttributeError: 'str' object has no attribute 'shp'

    --- END OUTPUT
    Last edited by bvdet; May 5 '11, 01:30 PM. Reason: Attempt to properly format code
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    I noticed one problem. On line 5 you make the assignment mxd2 = glob.glob('*.sh p') and on line 12 you again use the identifier mxd2 in the for loop.

    Comment

    • Jake S
      New Member
      • May 2011
      • 5

      #3
      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.

      Code:
      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()
          array.add(pnt1)
          array.add(pnt2)
          array.add(pnt3)
          array.add(pnt4)
          array.add(pnt1)
          polygon = arcpy.Polygon(array)
          arcpy.CopyFeatures_management(polygon, "Polygon_Extent" + "_" + str(y))
          y = y + 1
      
      
      list = []
      
      lstFCs = arcpy.ListFeatureClasses("Polygon_Extent*")
      for fc in lstFCs:
          list.append(fc)
      
      arcpy.Merge_management(list, "Extent")
      
      for item in list:
          arcpy.Delete_management(item)

      Comment

      Working...