11

I am trying to convert some python script to display a table (based on a dbf) of features located within a specific data driven page. So far, I have the script successfully able to refresh the map to the specific table, but it does not update the table.

I have it set-up as three text boxes that should be updated with three specific fields when the user runs the script from ArcToolbox.

Any suggestions on why my table is not updating?

import arcpy, sys, os

#Reference current MXD
mxd = arcpy.mapping.MapDocument("current")

#Get input parameter
Name = arcpy.GetParameterAsText(0)

#Reference  data frames
mapatlasDF = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
locatorDF = arcpy.mapping.ListDataFrames(mxd, "Locator Map")[0]

#Reference appropriate layers
atlasLyr = arcpy.mapping.ListLayers(mxd, "PinalCreekMapAtlas_HalfMile", mapatlasDF)[0]
locatorLyr = arcpy.mapping.ListLayers(mxd, "Locator Map", locatorDF)[0]
atlasoutlineLyr = arcpy.mapping.ListLayers(mxd, "Map Atlas Outline", locatorDF)[0]

#Reference layout elements by calling ListLayoutElements 
for elm in arcpy.mapping.ListLayoutElements(mxd):
  if elm.name =="Table1Column1": tab1Col1Txt = elm
  if elm.name =="Table1Column2": tab1Col2Txt = elm
  if elm.name =="Table1Column3": tab1Col3Txt = elm

#Reference the Data Driven Page object
ddp = mxd.dataDrivenPages

#Set the current page to be the one selected in the script tool
arcpy.AddMessage(Name)

pageID = mxd.dataDrivenPages.getPageIDFromName(str(Name))
mxd.dataDrivenPages.currentPageID = pageID

#Set the appropriate definition queries
atlasLyr.definitionQuery = "Name = '" + Name +  "'"
locatorLyr.definitionQuery = "Name = '" + Name +  "'"
atlasoutlineLyr.definitionQuery = "Name <> '" + Name +  "'"

#Update Sheet Index data frame
arcpy.SelectLayerByAttribute_management(locatorLyr, "NEW_SELECTION", "\"Name\" = '" + Name + "'")
locatorDF.panToExtent(locatorLyr.getSelectedExtent())

#Reference Affected Parcels table and select appropriate records
parcelTable = arcpy.mapping.ListTableViews(mxd, "AffectedParcels")[0]

#Build query and create search cursor to loop through rows
parcelFieldValue = "Page " + Name
queryExp = "\"MapPage\" = '" + parcelFieldValue + "'"  #e.g., "MapPage" = 'Page 01'
parcelRows = arcpy.SearchCursor(parcelTable.dataSource, queryExp)

#Clear all table text values
tab1Col1Txt.text = " "; tab1Col2Txt.text = " "; tab1Col3Txt.text = " "

#iteate through each row, update appropiate text
count = 0
for row in parcelRows:
  if count < 30: #Table1 - static position
    tab1Col1Txt.text = tab1Col1Txt.text + row.getValue("OwnerName") +"\n"
    tab1Col2Txt.text = tab1Col2Txt.text + row.getValue("APN") + "\n"
    tab1Col3Txt.text = tab1Col3Txt.text + row.getValue("LengthTrail") + "\n"
  if count ==30:  
    arcpy.AddMessage("Table Overflow") #The code could be reworked to show the last 90 records
  count = count + 1

arcpy.RefreshActiveView()
arcpy.AddMessage("PROCESS COMPLETED")
3
  • I'd start by trying to cut down your script to a simpler example. Are the objects being returned by ListLayoutElements of type TextElement? Can you update a single text value in the script, without any of the other code?
    – scw
    Commented Jun 4, 2013 at 8:13
  • as scw said, are the elements actually being returned? I would add arcpy.AddMessage("Found Table1Column1") in each if statment and then add arcpy.AddMessage(tab1Col1Txt.text + tab1Col2Txt.text + tab1Col3Txt.text) in the if count < 30 area. This will give a better idea of where the problem is occurring.
    – eseglem
    Commented Aug 3, 2013 at 13:57
  • From the code is not clear where are the tab1Col1Txt, tab1Col2Txt and tab1Col3Txt objects are defined. First try to verify what gets returned by the row.getValue part
    – Matej
    Commented Jan 31, 2014 at 20:45

1 Answer 1

2

Perhaps these examples could help:

DDP with Dynamic Tables And Graphs 10.1_v1

This sample demonstrates how the arcpy.mapping API is used to extend the capabilities of Data Driven Pages (DDP) to produce a map series truly dynamic tables and graphs

arcpy.mapping Map Book with Dynamic Graphic Tables

This project incorporates Data Driven Pages and arcpy.mapping to build a map series that includes dynamic graphic tables.

1
  • 1
    Can you provide more content in your answers? Link only answers are not preferred since the link may change over time.
    – artwork21
    Commented Jan 15, 2014 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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