根据以下SE Q / A,我假设您已经成功安装了comtypes:
片段:
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()
可以自定义此代码以更新活动ArcMap会话中打开的mxd的属性。