Automating capture of Extent from multiple mxds with multiple dataframes

3880
35
04-19-2011 03:14 PM
George_ChandeepCorea
New Contributor III
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 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.

Would appreciate your help in completing this script.

Thanks,

>>> import arcpy, os, glob
... #path = 'c:\\temp\\george\\'
... path = 'P:\\2011\\Job_031_TownPlanning_SeriesProduction\\Working\\mxd\\1'
... os.chdir(path)
... mxds_List = glob.glob('*.mxd')
... count_Mapdocs = len(mxds_List)
... print 'Processing ' + str(count_Mapdocs) + 'map documents...'
... #Create Polygon Shapefile
... arcpy.CreateFeatureclass_management(path, 'extents.shp', "POLYGON")
... #Start Loop
... for mxd 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 = mxd.shp
...     #Write in table scale
...     #Write in table

Processing 14map documents...

Runtime error <type 'exceptions.AttributeError'>: 'str' object has no attribute 'shp'
Tags (2)
0 Kudos
35 Replies
LT
by
Occasional Contributor
Looks like has to do with the array object.  Points are fine going in, but get set to zero by that array method call.
0 Kudos
LT
by
Occasional Contributor
Argh.  Subtle but important distinction:

    
    point.x = pt[0]
    point.y = pt[1]


Should have X and Y instead of x and y.

arcpy silently accepts and sets values to zero.  SOMEONE please change this behavior.   (wasted 3 hrs on this!)
0 Kudos
TomMagdaleno
Occasional Contributor III
Thank you Nicholas for making an awesome script!  You saved me a lot of time.  Kudos
0 Kudos
HeatherCowley1
New Contributor

I am very new to Python (and coding), and I cannot manage to get any of the codes on this page to work. All but one ends in errors, and the one that doesn't, posted by Jake Skinner on May 10, 2011, seems to freeze or something. I can't tell if it is actually doing anything, so I exit out.

I tried Nicholas Peihl's Map Index found here: npeihl / MapIndexTool / wiki / Home — Bitbucket . It has so much potential of being the perfect tool for what I need, but it only works on the biggest map extent in each MXD, and unfortunately, my series of maps and data frame in question is not the biggest map on the layout (think of it as an insert). I tried changing it to a for loop instead of an if else, but upon running it tells me it is formatted incorrectly, and I can't find the problem. Same problem if I change it to look for a specific data frame name. If I could get it to work, I would add another field where it includes the Data Frame name.

Can somebody help me?

0 Kudos
deleted-user-1T_bOHag6M8d
Occasional Contributor

Hi Heather,

Can you post the failing code you tried with the for loop? Then I could probably give you some advice.

0 Kudos
HeatherCowley1
New Contributor

I have attached two files I have tried to modify below (I seemed to have deleted the real for loop one, but these are still good enough examples of my attempts). It could be me and how I am attempting to run them, as I know you bundled them up into a nice ArcTool box, but when I try to replace the py file, it seems to not acknowledge my changes and runs as you originally wrote it. So, when I go into IDLE and run it with my changes, I always get the following:

Thank you so much for looking at this!

0 Kudos
deleted-user-1T_bOHag6M8d
Occasional Contributor

Hi Heather,

The map_index_dfname.py appears to be very close to working. But you have a reference to a pFrame variable which doesn't exist. In your for loop, you are creating the df variable. Maybe try changing pFrame to df.

0 Kudos
HeatherCowley1
New Contributor

I can't tell if I am making headway or not with that window complaining about the formatting. I cannot find any spaces. I'm such a noob in over my head.

The idea to call for a specific data frame came from the bottom of this page: ListDataFrames—Help | ArcGIS for Desktop 

Thank you!

0 Kudos
deleted-user-1T_bOHag6M8d
Occasional Contributor

lines starting in pink are using tabs

Hi Heather,

The second error in the popup describes the issue. Look at the screenshot above. My IDE shows lines with pink highlighting that begin with tabs. Every other line using spaces.  Either replace the tabs with the correct number of spaces or vice versa. You can't have both.

Whether you use tabs or spaces is personal preference.

0 Kudos
HeatherCowley1
New Contributor

Hi Nicholas, thank you for being so patient with me. I feel like I'm asking such basic questions, but I am making progress!

Long story short, I have tried numerous methods, but what finally worked was deleting every indent on every line and hitting tab. Once I did it to the pink region, it was willing to work.

I then put the file in the same folder as my MXDs, and tried to run it and I got a line 30 "TypeError: object of type 'NoneType' has no len()", which I read was probably because it was waiting on an input (python - What is a 'NoneType' object? - Stack Overflow).

I renamed and replaced the file in your Scripts folder and reloaded the Map Index Toolbox into catalog, but this is a whole new realm for me, and it is obviously not pulling the py script when it runs. The results are the same as if I hadn't changed any code.  I tried right clicking it in ArcToolbox and importing my py script, and that failed.

Creating the new Map Index shapefile
Opening map document Z:\Projects\60132\Maps\Strip Maps\Arc\0027-2016.mxd
Failed script MapIndex...

Traceback (most recent call last):
  File "C:\Users\heather\Documents\ArcGIS\AddIns\npeihl-mapindextool-0da4e723ca4a\Map Index Toolbox.tbx#MapIndex.py", line 45, in <module>
  File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\utils.py", line 182, in fn_
    return fn(*args, **kw)
  File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\mapping.py", line 1496, in ListDataFrames
    result = mixins.MapDocumentMixin(map_document).listDataFrames(wildcard)
  File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\arcobjects\mixins.py", line 745, in listDataFrames
    return list(reversed([fr for fr in self.dataFrames if wildcardmatch(wildcard, fr.name)]))
  File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\arcobjects\mixins.py", line 710, in dataFrames
    return map(convertArcObjectToPythonObject, self.pageLayout.dataFrames)
  File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\arcobjects\mixins.py", line 694, in pageLayout
    return convertArcObjectToPythonObject(self._mxd._arc_object.pageLayout)
AttributeError: 'unicode' object has no attribute '_arc_object'

Failed to execute (MapIndex).
Failed at Fri Sep 16 10:03:50 2016 (Elapsed Time: 4.12 seconds)

Suggestions?

0 Kudos