I am changing sources on MXDs in differents offices using ArcPy and ArcGIS 10.0. As observed here, the printer settings revert to the default printer when the instruction mxd.save() is sent.
Losing the printer is a minor issue in my case, but it becomes major if the print option "Scale map elements proportionally to changes in page size" is ticked while the "Use Printer Paper Settings" is selected. The screenshot below is my worst-case scenario, the best case would be unchecking both tick-boxes.
I would like to use comtypes to check the value of that option and set it to False (unticked) before saving the MXD - the idea is to call this as a function from an existing ArcPy script. (primary goal)
To secure the print settings further, I would ideally also like to untick the "Use printer setting" box if it is ticked. (secondary goal)
Can anyone help?
Answer
I assume you have installed comtypes successfully, according to the following SE Q/A:
Snippet:
import arcpy
from snippets102 import *
from comtypes.client import GetModule, CreateObject
import comtypes.gen.esriFramework as esriFramework
import comtypes.gen.esriArcMapUI as esriArcMapUI
import comtypes.gen.esriCarto as esriCarto
pMapDoc = CreateObject(esriCarto.MapDocument, interface=esriCarto.IMapDocument)
path = r'D:\my.mxd'
pMapDoc.Open(path)
pageLayoutActiveView = CType(pMapDoc.PageLayout,esriCarto.IActiveView)
p = pMapDoc.PageLayout.Page
#unchecking "Scale map elements proportionally to changes in page size"
p.StretchGraphicsWithPage = False
#setting the size manually suppresses the default behaviour of "Use Printer Paper Settings"
(width,height)=p.QuerySize()
p.Units=1 #1 is for Inches
p.PutCustomSize(width,height) #sizez of a4
pMapDoc.Save()
This code can be customized to update the properties of an opened mxd in an active ArcMap session.
No comments:
Post a Comment