I need to change the spatial reference of an existing MXD programmatically. In ArcMap UI, I would take the following steps: 1) Open the data frame properties and go to the Coordinate System tab; 2) click on little globe button (Add Coordinate System) and choose New Projected Coordinate System; 3) choose Mercator; 4) enter custom name for the coordinate system; 5) change the Standard_Parallel_1 parameter to the appropriate value; and 6) Save/PressOK. Ultimately, I need to automate this process over hundreds of MXDs.
I am really very confused about where even to start. My research has turned up a lot of references to IProjectedCoordinateSystemEdit and related classes and interfaces and to reading/writing parameters to arrays with IParamter and related, but I am finding a lot of the information confusing. So, which Interfaces/Classes should I start with, and what is the most concise way of accomplishing automation of the process I describe above?
My code currently opens the MXD to be processed in an IMapDocument and changes a suite of PageLayout and Map settings. What is left is the changing of the spatial reference. Thanks for any guidance you can offer.
UPDATE (@Hornbydd) Here is the Python main body code. (BTW, when accessing ArcObjects from Python, one thing that Python can't do is implement interfaces, so responding to events and extending ArcGIS isn't possible. I have yet to find any com objects that it can't access, though.)
f = open(chartprops, 'r') i = 0 for chrt in f: if i == 0: #skip the header i = i + 1 continue props = chrt.split(',') chartnm = props scale = float(props) latorig = props pixwidth = float(props) pixheight = float(props) if len(props) > 5: pprwidth = float(props) pprheight = float(props) pprorienttxt = props else: pprwidth = pixwidth / 254.0 pprheight = pixheight / 254.0 if pprwidth > pprheight: pprorienttxt = 'LANDSCAPE' else: pprorienttxt = 'PORTRAIT' if pprorienttxt == 'PORTRAIT': pprorient = 1 else: pprorient = 2 #copy template chart MXD to chart output location #==== WARNING! ==== # If the mxd already exists in the detination folder, # it will be overwritten #================== destmxd = outloc + os.path.sep + chartnm + '.mxd' shutil.copy(templt, destmxd) pMapDoc = NewObj(esriCarto.MapDocument, esriCarto.IMapDocument) pMapDoc.Open(destmxd) pPgLayout = pMapDoc.PageLayout pPgLayout3 = CType(pPgLayout, esriCarto.IPageLayout3) pPage = pPageLayout3.Page pPage.Units(esriInches) pPage.PutCustomSize(pprwidth, pprheight) pPage.Orientation(pprorient) pMap = pMapDoc.Map pMap.MapUnits(esriInches) pMap.SetPageSize(pprwidth, pprheight) pMap.ReferenceScale(1.0/scale) pMap.MapScale(1.0/scale) pMapDoc.Close() i = i + 1 f.close()