1

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
1
  • Check your indentation after for LayerName in LayersToExport: above (although your error messages suggest the indentation is correct in your code, it isn't correct above).
    – Midavalo
    Mar 4, 2016 at 17:55

1 Answer 1

2

It looks like the ExportToJPEG is missing the DataFrame parameter. You need to change the line

arcpy.mapping.ExportToJPEG(CurrentMXD, Output_jpg, resolution=300, jpeg_quality=95)

to

arcpy.mapping.ExportToJPEG(CurrentMXD, Output_jpg, CurrentDF, resolution=300, jpeg_quality=95)

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.