1

I encountered some problematic arcpy behavior when running this code. This code eventually creates an inventory of source data per layer used for each map contained in a directory (mxd_dir).

# get list of all mxd filenames within directory to inventory
mxd_list = os.path.listdir(mxd_dir)
# list of full file path
fp_mxd_list = [os.path.join(mxd_dir, mxd) for mxd in mxd_list]
# get mxd_obj
for fp_mxd in fp_mxd_list:
    mxd_obj = arcpy.mapping.MapDocument(fp_mxd)
    # HERE IS WHERE ARCPY EXITS PYTHON
    arcpy.mapping.ListLayers(mxd)

Arcpy is breaking from the Python script without throwing an exception/error or any indication of what failed - Python interpreter simply quits. This is occurring with arcpy.mapping.ListLayers on a particular mxd. The file is not open anywhere, conforms with file naming conventions for the other files, no broken file paths.

I am not sure why arcpy does not print an exception statement to help diagnose failure.

Note: since posting I have determined that it was CAD data used within an MXD causing the issue, so it should be mentioned that the problematic mxd file contains CAD data. I have addressed the CAD issue in the comments essentially as the solution.

ArcMap 10.6, Windows 64 bit.

4
  • At the moment you have only presented a copy/paste of two lines from your code when what we need to try and reproduce your problem is a code snippet.
    – PolyGeo
    Commented Jan 4, 2021 at 20:55
  • At the moment your question makes no mention that you are using CAD data as the source of any problematic layers. Please use the edit button beneath your question to revise it with any additional information that you think may be relevant to it.
    – PolyGeo
    Commented Jan 4, 2021 at 22:05
  • Comments are not part of your question and may be deleted at any time. Please transfer anything within them that is relevant to your question into your question body.
    – PolyGeo
    Commented Jan 4, 2021 at 22:51
  • You cannot mark a comment as an answer. Answers should only be written in the area reserved for answers.
    – PolyGeo
    Commented Jan 14, 2021 at 6:51

1 Answer 1

0

Culprit found - CAD data (kind of) - arcpy.mapping.ListLayers() fails with certain data types in this case CAD data, specifically CAD FOLDERS. No error message is thrown, Python simply exits. I'm not knowledgeable enough on CAD to specify the exact folder structure, schema, etc. but it is the bread and butter structure engineers will send from AutoCAD when sharing design drawings. Its basic structure is a top directory which contains references to all the DWG files that create the CAD drawings. The ArcMap will draw the data onto a map, but the ListLayers method will error out of Python if called on this group layer. Using DWG files individually will not result in an error.

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.