I have some spatial bookmarks in my MXD file and i want to export each and every bookmark as one jpeg file. I have found below code but it is giving an error.

import arcpy

mxd = arcpy.mapping.MapDocument(r"C:\SOFTWARE\Python\test.mxd")

df = arcpy.mapping.ListDataFrames(mxd, "test")[0]

for bkmk in arcpy.mapping.ListBookmarks(mxd, data_frame=df):

    df.extent = bkmk.extent

    outFile = r"C:\SOFTWARE\Python\Out\\" + bkmk.name + ".jpg"

    arcpy.mapping.ExportToJPEG(mxd, outFile, df)

del mxd

After running above code, it is giving error as 

df = arcpy.mapping.ListDataFrames(mxd, "test")[0]

IndexError: list index out of range

How do I export each bookmark as jpeg with the above code?


2 Answers 2


My guess is that your data frame is not called 'test' so the call is returning an empty list.

This answer explains a similar call in a bit more detail: https://gis.stackexchange.com/a/80237/43

If you are adventurous, try:

 df = arcpy.mapping.ListDataFrames(mxd, '')[0]

This will return all the data frames in your MXD, then select the first one.


Check whether the data frame is named "test".

The second argument in df = arcpy.mapping.ListDataFrames(mxd, "test")[0] should be the name of the data frame.

  • yes. my data frame is not test. Its Test1. once i changed, it works
    – Arb
    Apr 21, 2017 at 17:30

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.