Drob88

ArcPy Select / ZoomTo/ the attribute records and write to text the Map Scale

Discussion created by Drob88 on Aug 14, 2013
Hello Group,

I am trying to use ArcPy to extract the individual mxd map scale (the data frame scale of the map after selecting a record and using the "ZoomTo" function)  of each record in a feature class, and writing it to a text file.  I have some python code that works through a For: Loop, but it only returns the first record zoomed in map df.scale, instead of iterating through the entire attribute table.  I realize I need to identify the individual rows within the loop, but I'm failing to grasp how to do that.  So I'm looking for any help on how to correctly code this process.  Here is what I'm working with minus the end process of writing the results to a text file. (I'm a newbie to python as well, but I'm trying  :)  )  ps. the "print" line is there to see the results before writing them to text.

>>> import arcpy
>>> from arcpy import env
>>> env.workspace = "D:/Data/Workspace"
>>> from arcpy import env
>>> mxd = arcpy.mapping.MapDocument("Current")
>>> df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
>>> rows = arcpy.SearchCursor("ArcPyLoop")
>>> row = rows.next()
>>> arcpy.SelectLayerByAttribute_management("ArcPyLoop", "NEW_SELECTION")
<Result 'ArcPyLoop'>
>>> for record in rows:
...     df.zoomToSelectedFeatures()
...     print df.scale
...     row = rows.next()
...     arcpy.RefreshActiveView()
...
...
115470.404513 (1st df.scale repeated for all rows in attribute table)

Thank you for any help or guidance    - Drob

Outcomes