How would I go about identifying all the mxd files that have graphics?

I reckon it's close to:

import arcpy
import os

srcPath = "my_path"

mxd_lst = [f for f in os.listdir(srcPath) if f.endswith('.mxd')]

for mxd in mxd_lst:
    for dfrm in arcpy.mapping.ListDataFrames(mxd):

        if "GRAPHIC_ELEMENT" in dfrm != None:  # *I'm making this line up*
            print(mxd + " has graphic elements")

            print(mxd + " does not contain graphics")

1 Answer 1


arcpy.mapping.ListLayoutElements is what you need. See the docs for more info on other element types (e.g. text-elements)

I modified your code slightly.

import arcpy
import os

srcPath = r"\\somePath\to\MapFiles"

mxd_lst = [os.path.join(srcPath, f) for f in os.listdir(srcPath) if f.lower().endswith('.mxd')]

mxds_with_graphicElms = []
for mxdPath in mxd_lst:
    mxd = arcpy.mapping.MapDocument(mxdPath)
    graphicElms = arcpy.mapping.ListLayoutElements(mxd, "GRAPHIC_ELEMENT", "*")
    if graphicElms:
        print(mxdPath + " has graphic elements")
print (str(mxds_with_graphicElms))
  • Cheers. Runs well. As a point of clarification, ListLayoutElements searches dataframes well as layouts?
    – CreekGeek
    Commented Jul 2, 2021 at 3:49
  • No, you may be mixing up ArcPro and ArcMap terminology. In ArcMap, to search Dataframes, use the arcpy.mapping.ListDataFrames() method. This will only find data frame objects. Once the DF is identified, then you could do a nested for loop with, for example, arcpy.mapping.ListLayers().
    – Keggering
    Commented Jul 2, 2021 at 6:00
  • Unlikely, but possible. To clarify: in an ArcMap 10.7 GUI, "Data View" would be proper, but one would Insert > Data Frame. In standalone Python, mapping.ListDataFrames accesses the same objects. A layout is a layout since the ArcView days. By 'graphics', I mean objects created with the Draw toolbar...whose display is controlled as a matter of annotation in the Frame properties, but if converting to features (e.g. via right-clicking the Data Frame in the TOC), one selects "Convert Graphics to Features". I'm interested in point graphics in any frame, hence nested FOR loops in original post.
    – CreekGeek
    Commented Jul 2, 2021 at 9:17
  • I see. I do not believe ArcPy has access to map-annotation elements. Certainly listLayoutElements does not. Per ESRI: "ListLayoutElements only returns elements from a page layout and not map annotation elements that may exist within a data frame." desktop.arcgis.com/en/arcmap/10.7/analyze/arcpy-mapping/…
    – Keggering
    Commented Jul 2, 2021 at 15:42
  • Also check out the answer from @blah238 here: link
    – Keggering
    Commented Jul 2, 2021 at 16:07

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.