ArcMap 10 - Change coordinate system in mxd file

Discussion created by rdharles on May 26, 2010
Latest reply on May 23, 2012 by nahmed-esristaff
I want to change the coordinate system in the Data Frame Properties through arcpy.mapping.MapDocument()  using python.


Here's the code I came up with:
import arcpy, sys
mxd = arcpy.mapping.MapDocument("base.mxd")

prjList = "q:/python/prj/"

# Read in the coordinate system definition
prj = arcpy.SpatialReference(prjList+sys.argv[1]+".prj")
# Get the code (e.g. 2288 = "NAD_1983_StatePlane_California_VI_FIPS_0406_Feet")
code = prj.PCSCode

df = arcpy.mapping.ListDataFrames(mxd)[0]
sr = df.spatialReference
sr.PCSCode = code
df.spatialRefence = sr

del mxd
This code works ONLY if I first open the mxd file and hit the clear button (see image above).
If the coordinate system isn't cleared first, the code runs through without error but doesn't change the coordinate system.
Not sure if this is a bug or not? (If it's not a bug, I can find or figure out any way to clear the coordinate system through scripting).
Anyone have any experience with this?