Everything seems to work just fine with the code below except that no features draw in the layer that is being queried. All I want to do is create a jpeg for each record in my geodatabase feature class of point locations.Is there something wrong with my query syntax? I cannot figure it out!try:
import arcpy, sys, traceback
print "Working..."
mxdPath = r"Z:\GISpublic\GerryG\WaterResources\WaterSampleSiteAutoMap\WaterSampleSiteAutoMap2.mxd"
mxd = arcpy.mapping.MapDocument(mxdPath)
df = arcpy.mapping.ListDataFrames(mxd)[0]
lyr = arcpy.mapping.ListLayers(mxd, "WaterSampleSiteMaster", df)[0]
print lyr.dataSource
theAttribute = "SiteID"
#GetAListOfEachAttribute
listOfAttributes = []
print "Start cursor"
rows = arcpy.SearchCursor(lyr.dataSource)
for row in rows:
listOfAttributes.append(row.getValue(theAttribute))
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
if elm.name == 'gbglabeler':
elm = elm
print elm.name
break
for item in listOfAttributes:
#GBGquery = "\"" + theAttribute + "\" = " + "'" + item + "'"
GBGquery = '"SiteID" =' + '\''+ item + '\''
print "Working on: ",item
print GBGquery
lyr.definitionQuery = GBGquery
elm.text = "Site: " + item
outputjpg = "Z:\GISpublic\GerryG\WaterResources\WaterSampleSiteAutoMap\SiteMaps\\" + item + ".jpg"
arcpy.RefreshActiveView()
arcpy.mapping.ExportToJPEG (mxd, outputjpg)
print "done"
except arcpy.ExecuteError:
msgs = arcpy.GetMessages(2)
arcpy.AddError(msgs)
#If the error is with the script, or with python, find error and report it to the screen...
except:
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages(2) + "\n"
arcpy.AddError(pymsg)
arcpy.AddError(msgs)