I'm trying to implement the code mentioned on this post: Best way to have title which includes dynamic text of a layer name? and I'm getting the error below. I am a novice and know nearly nothing about python. I've been trying to troubleshoot on my own but this is over my head.
import arcpy, os
#Map document stuff
CurrentMXD = arcpy.mapping.MapDocument("CURRENT")
CurrentDF = CurrentMXD.activeDataFrame
#Output map directory
Output_dir = "C:\temp"
#Iterate through layer names
LayersToExport = ["Layer name 1","Layer name 2"]
for LayerName in LayersToExport:
#Get current layer, make visible
Layer = arcpy.mapping.ListLayers(CurrentMXD, LayerName, CurrentDF)[0]
Layer.visible = True
#Change title text
TextElement = arcpy.mapping.ListLayoutElements(CurrentMXD, "TEXT_ELEMENT","TitleText")[0]
TextElement.text = Layer.name
#Get output JPG filename, remove existing, export
Output_jpg = os.path.join(Output_dir,LayerName+".jpg")
if os.path.exists(Output_jpg): os.remove(Output_jpg)
arcpy.mapping.ExportToJPEG(CurrentMXD, Output_jpg, resolution=300, jpeg_quality=95)
#Make layer invisible again
Layer.visible = False
Runtime error
Traceback (most recent call last):
File "<string>", line 25, in <module>
File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\utils.py", line 182, in fn_
return fn(*args, **kw)
File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\mapping.py", line 1026, in ExportToJPEG
layout.exportToJPEG(*args)
File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\utils.py", line 182, in fn_
return fn(*args, **kw)
File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\arcobjects\mixins.py", line 568, in exportToJPEG
return self._arc_object.exportToJPEG(*args)
AttributeError: PageLayoutObject: Error in executing ExportToJPEG
for LayerName in LayersToExport:
above (although your error messages suggest the indentation is correct in your code, it isn't correct above).