Script Error: Populating mxd document properties with arcpy.mapping module

1936
2
08-25-2011 12:39 PM
JamesKellough
New Contributor II
Hi folks,

I am new to the arcpy module at version 10. I have a number of mxd's with the same theme that will ultimately have either the same or very similar document properties. To save time typing, I want to write and run a script from the python window to automatically populate each mxd's document properties. This was pretty easy up until I wanted to populate the Title property with the mxd's name. After searching the forums and other online sources it seems the best way to do this is by parsing the filename out of the file path. I found some code samples to help me do this but can't get them to work (see highlighted code below) any help a more proficient python scripter can provide would be greatly appreciated.

Here is my code. I am having trouble making the highlighted code work; if I remove it from the script all else works just fine.

import os
mxd = arcpy.mapping.MapDocument("CURRENT")
P = mxd.filePath
P.split('/')[-1]
mxd.title = P
mxd.summary = "blah,blah, blah."
mxd.author = "James Kellough"
mxd.credits = "My Company"
mxd.description = "blah, blah, blah"
mxd.tags = "Script, Python, Arcpy"
del mxd

Thanks kindly,

James Kellough
Tags (2)
0 Kudos
2 Replies
MathewCoyle
Frequent Contributor
I think you need to save your split as a new variable, or overwrite the existing one
Edit: also the slash is a little out of whack when I tested it, try this "\\"
mxd = arcpy.mapping.MapDocument("CURRENT")
P = mxd.filePath
P = P.split("\\")[-1]
mxd.title = P
mxd.summary = "blah,blah, blah."
mxd.author = "James Kellough"
mxd.credits = "My Company"
mxd.description = "blah, blah, blah"
mxd.tags = "Script, Python, Arcpy"
del mxd
0 Kudos
JamesKellough
New Contributor II
Thanks very much Mathew, that minor change worked perfectly! Don't know how I could have missed that :o.
Cheers,

James
0 Kudos