AssertionError: Invalid MXD filename...why?

3667
4
Jump to solution
05-14-2012 07:29 AM
RichardThurau
Occasional Contributor
Hi,
I have a simple script for batch exporting .mxds to .PNG:

import arcpy, os ws = arcpy.env.workspace = r"X:\DATA\07_Reporting\MapDocuments\UTC_Factsheet_ANCs" outDir = r"C:\_Rich\Project_Temp\dc\MapTest"  mapList = arcpy.ListFiles("*.mxd") for m in mapList:     print m     mxd = arcpy.mapping.MapDocument(ws + m)     #arcpy.mapping.MapDocument(mxd)     arcpy.mapping.ExportToPNG(mxd, outDir + '\\' + str(m))     del mxd


I've used this code several times before. I don't think I've modified it at all, except for the workspace and outdirectory.

Today, I am getting the following error:
Traceback (most recent call last):
  File "X:\DATA\INRMP_JPG\Tools\Scripts\export_mxd_to_PNG_Smoky.py", line 10, in <module>
    mxd = arcpy.mapping.MapDocument(m)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\arcobjects\mixins.py", line 443, in __init__
    assert (os.path.isfile(mxd) or (mxd.lower() == "current")), gp.getIDMessage(89004, "Invalid MXD filename")
AssertionError: Invalid MXD filename.

Note: Neither my filenames or mxd names have any spaces in them (although that hopefully would be okay).

I need this bad because i have many maps to convert.
Help on this would be awesome.

Running Arcgis 10.0 sp4
win7 64bit

Thanks
Rich
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MathewCoyle
Frequent Contributor
This looks like the problem here.
mxd = arcpy.mapping.MapDocument(ws + m)

This would output this
"X:\DATA\07_Reporting\MapDocuments\UTC_Factsheet_ANCsyour_mxd.mxd"

You'd want something like
mxd = arcpy.mapping.MapDocument(os.path.join(ws,m))

View solution in original post

0 Kudos
4 Replies
MathewCoyle
Frequent Contributor
This looks like the problem here.
mxd = arcpy.mapping.MapDocument(ws + m)

This would output this
"X:\DATA\07_Reporting\MapDocuments\UTC_Factsheet_ANCsyour_mxd.mxd"

You'd want something like
mxd = arcpy.mapping.MapDocument(os.path.join(ws,m))
0 Kudos
RichardThurau
Occasional Contributor
I'll have to chalk this one up to Monday morning 🙂

Thanks Mathew!!
0 Kudos
ClarkMitten
New Contributor
Richard or Matthew,

Do either of you know how to convert this to be used as a tool?

Thanks
0 Kudos
RichardThurau
Occasional Contributor
You can create tools from python scripts following the process here: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001500000006000000.htm

Follow these directions to create a tool that can be saved in any ArcToolbox, which is a great way to organize scripts btw.

Hope this helps.

RT
0 Kudos