Saturday, 5 May 2018

arcpy - Using Python to disable Scale map elements proportionally to changes in page size?


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.


enter image description here





  • 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

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...