Seems to me that you should put the export to pdf statement in the GroupLayer true portion of the if else clause. I would think it is currently exporting every layer out to a pdf since the export to pdf statement is outside the if else clause but within the for loop.
You are right. It worked perfectly. Now I dont know if it is easy to do but I am trying to update figure title name and source ffor each PDF using a table. Any idea how to do so?Thanks,Aleximport arcpy, os, sys
myPath = os.path.dirname(sys.argv[0])
myMap = arcpy.mapping.MapDocument(myPath + r"/MyMap2.mxd")
layer = arcpy.mapping.ListLayers(myMap, "Map_Elem_Table_v2")[0]
rows = arcpy.SearchCursor(layer)
# Legend Items
fignumElem = arcpy.mapping.ListLayoutElements(myMap, "TEXT_ELEMENT","FigNumber")[0]
titleElem = arcpy.mapping.ListLayoutElements(myMap, "TEXT_ELEMENT","FigTitle")[0]
sourceElem = arcpy.mapping.ListLayoutElements(myMap, "TEXT_ELEMENT","FigSource")[0]
#create a cursor to access values from attribute table
for row in rows:
fignumElem.text = str(row.FigNumber)
titleElem.text = unicode(row.FigTitle)
sourceElem.text = str(row.FigSource)
# Loop through each Group layer and export to PDF
for lyr in layer:
if lyr.isGroupLayer:
print "Turning on Layer " + lyr.name
lyr.visible = True
print "exporting map"
arcpy.mapping.ExportToPDF(myMap, myPath + str(lyr.name) + ".pdf")
else:
print "Turning off layer " + lyr.name
lyr.visible = False