using arcpy.env.workspace to open a MXD

3594
2
Jump to solution
06-18-2012 07:59 AM
JohnNerge
New Contributor III
So my script was working on Friday but doesn't anymore, and I can't figure out why. Basically, I am running into an error when trying to set the environment workspace and use it to open a MXD. Here is a dumbed down version of the piece of my code that is throwing an error (it throws the same error as what's in my actual code:

import arcpy

arcpy.env.workspace = "C:/test"

mapdoc = "test.mxd"

mxd = arcpy.mapping.MapDocument(mapdoc)

and here is the error:
>>> Traceback (most recent call last):
  File "C:\Python26\ArcGIS10.0\Lib\site-packages\pythonwin\pywin\framework\interact.py", line 558, in OnEditExecClipboard
    exec o in __main__.__dict__
  File "<clipboard>", line 7, in <module>
  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.

If I run arcpy.mapping.MapDocument("C:/test/test.mxd") it works fine, so I don't know where things are getting hung up. Please help, and thanks in advance to all for any input.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MathewCoyle
Frequent Contributor
It requires the full path. The MapDocument object does not respect workspaces.
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00s30000000r000000

View solution in original post

0 Kudos
2 Replies
MathewCoyle
Frequent Contributor
It requires the full path. The MapDocument object does not respect workspaces.
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00s30000000r000000
0 Kudos
JohnNerge
New Contributor III
It requires the full path. The MapDocument object does not respect workspaces.
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00s30000000r000000


Mathew,

Thanks, I guess I must have changed something about that between today and Friday, though for the life of me I don't really think I did.
0 Kudos