1

I have a topology that covers a big area. I cannot validate all at once 'cause I get errors. So I've created a grid that covers the area. Through a script runned from my .mxd I intend to: 1. itterate through each grid cell 2. set it as the current extent of the map, 3. use the tool "Validate Topology", having checked the option "VISIBLE_EXTENT".

The workflow sounds correct to me, but I'm blocked at the first two steps. Here's my code:

import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
gridLayer = arcpy.mapping.ListLayers(mxd, "Caroiaj_RO", df)[0] 


# Create SearchCursor
with arcpy.da.SearchCursor(gridLayer, ("GridName2")) as cursor:

# Start a loop that iterates through all rows 
    for row in cursor:

    # Clause to select only the current record
        whereClause = ' "GridName2" = ' + str(row.GridName2)

        # Select Layer by attribute
        arcpy.SelectLayerByAttribute_management(gridLayer, "NEW_SELECTION", whereClause)

        df.extent = gridLayer.getSelectedExtent(True)

        arcpy.RefreshActiveView()

del cursor, row
del mxd 

Thanx a lot!

1

I use the following code. First I ensure the first item in the TOC is my grid, and then I begin an edit session. I then enter the following code in the python window in ArcMap, making sure to define the topology path. I hope it helps.

import arcpy

# Find min and max values of a feature class field
def min_max(featureClass, fieldName):
    listItems = []
    rows = arcpy.SearchCursor(featureClass)
    for row in rows:
        listItems.append(row.getValue(fieldName))
    del rows
    listItems.sort()
    listMin = listItems[0]
    listMax = listItems[-1]
    return listMin, listMax

mxd = arcpy.mapping.MapDocument('CURRENT')
df = arcpy.mapping.ListDataFrames(mxd, 'Layers')[0] # get top df in mxd
layer = arcpy.mapping.ListLayers(mxd)[0] # get top layer in TOC
desc = arcpy.Describe(layer.dataSource)
fullpath = desc.catalogPath
counter, Max = min_max(fullpath, "OBJECTID") # get min and max values from FID field
topology = r"DEFINE_TOPOLOGY_PATH_HERE"
while counter <= Max:
    print("%s of %s" % (counter, Max))
    arcpy.SelectLayerByAttribute_management(layer, "NEW_SELECTION", '"OBJECTID" = ' + str(counter))
    df.extent = layer.getSelectedExtent()
    arcpy.RefreshActiveView()
    arcpy.ValidateTopology_management(topology, "VISIBLE_EXTENT")
    counter += 1

EDIT: You may have to change 'OBJECTID' to fit your data.

  • wow! thanx a lot! exactly what I needed!It works! – teva26 Oct 10 '13 at 6:46
0
  1. You're mixing up arcpy.da.SearchCursor and arcpy.SearchCursor. You can't do row.ColumnName on a list.
  2. What is the point of this script? It'll pan through each extent, but not stop for any period of time. It'll basically draw a map on screen, then immediately hop to the next.

Try this:

import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
gridLayer = arcpy.mapping.ListLayers(mxd, "Caroiaj_RO", df)[0] 

# Create SearchCursor
with arcpy.da.SearchCursor(gridLayer, ("GridName2")) as cursor:
    # Start a loop that iterates through all rows 
    for row in cursor:
        # Clause to select only the current record
        whereClause = ' "GridName2" = {}'.format(row[0])

        # Select Layer by attribute
        arcpy.SelectLayerByAttribute_management(gridLayer, "NEW_SELECTION", whereClause)

        df.extent = gridLayer.getSelectedExtent(True)
        arcpy.RefreshActiveView()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.