Print

Print


Would anyone mind taking a look at this Python code and telling me why it says my MXD filename is invalid?

 

import arcpy, os

 

path = r"I:\ARC\DATA\MXDs"

 

for root, dirs, files in os.walk(path):

    for fileName in files:

        fullPath = os.path.join(path, fileName)

        basename, extension = os.path.splitext(fullPath)

        mxd = arcpy.mapping.MapDocument(fullPath)

        if extension == ".mxd":           

            for df in arcpy.mapping.ListDataFrames(mxd):

                for lyr in arcpy.mapping.ListLayers(mxd,"",df):

                    findthis = value1

                    findthat = value2

                    if findthis in lyr.name or findthat in lyr.name:

                        lyr.replaceDataSource(r'I:/ARC/Data/ITrees.gdb','FILEGDB_WORKSPACE','Trees')

                        print(lyr.name + " - Layer Resourced")

                    else:

                        pass

                        print lyr.name + ": Pass"

                    arcpy.RefreshTOC()

                    arcpy.RefreshActiveView()

                    mxd.save()

print "--Script complete--"

---------------------------------------------------------------------------------------------------

Results:

 

Traceback (most recent call last):

  File "I:\ARC\Data\Expressions\Trees_Walk.py", line 9, in <module>

    mxd = arcpy.mapping.MapDocument(fullPath)

  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\arcobjects\mixins.py", line 609, in __init__

    assert (os.path.isfile(mxd) or (mxd.lower() == "current")), gp.getIDMessage(89004, "Invalid MXD filename")

AssertionError: Invalid MXD filename.

 

 

 

When I print the variable “fullPath” it looks something like this:

 

I:\ARC\DATA\MXDs\Clinton Base Map.mxd

 

But when I feed the value  into

 

mxd = arcpy.mapping.MapDocument(fullPath)

 

it doesn’t like it anymore

 

 

Kind regards,

 

Michael Lachance

Plant Protection Technician

ALB Eradication Program USDA APHIS

151 West Boylston Drive

Worcester, MA 01606

508.852.8050 (o)

508.414.5673 (c)

The USDA is an equal opportunity provider and employer.

Federal Relay Service (Voice/TTY/ASCII/Spanish) 1-800-877-8339

 

This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately.

 

------------------------------------------------------------------------- This list (NEARC-L) is an unmoderated discussion list for all NEARC Users.

If you no longer wish to receive e-mail from this list, you can remove yourself by going to http://listserv.uconn.edu/nearc-l.html.