I need the name of the current MXD (newbie question)

4211
2
07-14-2011 02:52 AM
BobMijwaard
New Contributor III
I have followed the Python course very recently and just finished my first script. To make it more generic I need to know the name of the current MXD

In the script I use:
mxd = arcpy.mapping.MapDocument("CURRENT")

How can I get the name of the used mxd. Tried os.path.basename(mxd) but that did not work. Got the error: MapDocument is unsubscriptable

Regards,

Bob
Tags (2)
0 Kudos
2 Replies
AndrewChapkowski
Esri Regular Contributor
The reason you cannot get the path is because mxd is an object, not a string path.  To get the path, you need to use the filePath property on the MapDocument object.

import os
import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
mapPath = mxd.filePath
fileName = os.path.basename(mapPath)
print fileName


If your map document isn't saved, you will get returned an empty string.
0 Kudos
BobMijwaard
New Contributor III
Thanks a lot.

Still learning.......

Regards,

Bob
0 Kudos