Select to view content in your preferred language

arcpy.RefreshActiveView

1481
3
06-16-2014 12:26 AM
JohnByrne
Deactivated User
Morning all,

I am trying to put together a script that automatically updates the active table in Data Driven Pages. I found the script from one of the user groups on here and I think I have managed to alter the script but there is showing an error in line 39 and line 40

arcpy.RefreshActiveView()
arcpy.AddMessage("Process Completed")

Not sure what to do to fix this as I am only learning python and scripting. I have attached a jpeg of the code in case it helps,

Many thanks
Tags (2)
0 Kudos
3 Replies
DanPatterson_Retired
MVP Emeritus
You are missing the closing bracket  )  in the line above hence it is erroring out
0 Kudos
JohnByrne
Deactivated User
Thanks Dan, silly error.

I am struggling to get the script to run and the problem seems to lay in my query and Search Cursor. It is giving me an error which says

Traceback (most recent call last):
  File "D:\Profiles\jByrne\Documents\DARD GIS\TEST SCRIPT\GridMon16_help.py", line 13, in <module>
    FP_sampleRows=arcpy.SearchCursor(GridTable.datasource, queryExp)
AttributeError: 'TextElement' object has no attribute 'datasource'

I have attached my code as well. I am running out of ideas and because I don't know it very well (started scripting friday!) I can't really see the wood for the trees.

import arcpy, os, sys
mxd=arcpy.mapping.MapDocument("current")
BUSID_TEMP=arcpy.GetParameterAsText(0)
LayersDF=arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
selLyr=arcpy.mapping.ListLayers(mxd, "FP_sample", LayersDF)[0]
for elm in arcpy.mapping.ListLayoutElements(mxd):
    if elm.name=="GridTable": GridTable = elm
ddp=mxd.dataDrivenPages
arcpy.AddMessage(BUSID_TEMP)
pageID=mxd.dataDrivenPages.getPageIDFromName(str(BUSID_TEMP))
mxd.dataDrivenPages.currentPageID=pageID
queryExp="\"BUSID_TEMP\"='"+BUSID_TEMP+"'"
FP_sampleRows=arcpy.SearchCursor(GridTable.datasource, queryExp)
revTable=arcpy.mapping.ListTableViews(mxd,"GridTable")
arcpy.RefreshActiveView()
arcpy.AddMessage("Process Completed")

Thanks
0 Kudos
AlexanderNohe1
Honored Contributor

Hi John Byrne‌,

It looks like the datasource attribute is not a property of that element.  I would recommend looking at the following documentation (ListLayoutElements (arcpy.mapping)) which can provide some insight into what each elements properties are.  The traceback error, which has the message: AttributeError: 'TextElement' object has no attribute 'datasource', lets us know that it is an issue with an attribute associated with a TextElement.  So we can look at our TextElement page and see that datasource is not an attribute of the textelements. Text Element (arcpy.mapping)

Does this help?

0 Kudos