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?
1 Answer 1
I assume you have installed comtypes successfully, according to the following SE Q/A:
Code
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.
-
Thanks you Farid! This looks very promising indeed!! I am away from the office, and will be able to test your code Friday pm - I will keep you posted of course . My thanks again!!Hélène– Hélène2016年02月04日 05:14:22 +00:00Commented Feb 4, 2016 at 5:14
-
Just to confirm, it works great! Do you know if it is possible te read the current page size? Thinking about reading it then applying it as p.PutCustomSize(), so I keep the original page size for each MXD.Hélène– Hélène2016年02月05日 18:27:55 +00:00Commented Feb 5, 2016 at 18:27
-
1Sure, simply add
(width,height)=p.QuerySize()
to the code and changep.PutCustomSize(width,height)
accordingly. See the updated code snippet!Farid Cheraghi– Farid Cheraghi2016年02月05日 23:50:57 +00:00Commented Feb 5, 2016 at 23:50
Explore related questions
See similar questions with these tags.