I have put together a python script which iterates through a directory of mxd files and outputs their paths, layers, fields, and descriptive information to a csv file. When I run the script, it successfully outputs the desired information for about half of the mxds in the directory, but does not output anything for the others.
After breaking the code apart and running it, I can confirm that the paths to these 'broken' mxds are being added to my initial lists with the others, but for some reason the arcpy.mapping.MapDocument(mxd) method is not able to retrieve their information. (I am passing the mxd paths to this method) My Main question is: what are some potential reasons as to why this method is working for some mxds but not others?
The problem might also lie within the arcpy.mapping.ListLayers(mxd) method.
here is the section of the script where this is happening: (ignore the indentation..the script runs but formatting is lost when I copy it over)
#Iterate through the list of ArcMap Documents...
for mxdpath in mxd_list:
#mxdname = os.path.split(mxdpath)
mxd = arcpy.mapping.MapDocument(mxdpath)
#Iterate through the ArcMap Document layers...
for layer in arcpy.mapping.ListLayers(mxd):
fList = arcpy.Describe(layer).fields
for field in fList:
fields.append( "Field = " + field.baseName)
layerattributes = [mxdpath,' ', layer.longName,' ', layer.dataSource,' ',fields]
#Write the attributes to the csv file...
there are exceptions thrown when the script encounters the mxds in question.
through visual studio the only information I can find is:
<source>Editor or Editor Extension</source>
<description>System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
at Microsoft.NodejsTools.Repl.ReplOutputClassifier.GetClassificationSpans(SnapshotSpan span)
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)</description>
I'm not sure how to interpret this, as there is nothing that I can discern to differentiate between the mxds which are working and those which aren't. And to be honest I'm not even entirely sure if this error is something related to the mxds or something to do with visual studio.
Any information is appreciated, unfortunately I cannot provide any info regarding the specific mxds as they contain confidential enterprise info, but if anyone has ideas I am happy to provide non specific info (cache or not?, size? etc..)