Zooming and Printing in Python

318
4
02-18-2011 12:38 PM
MikePowell
New Contributor II
Is it possible to zoom in on and area and print without actually opening ArcMap. Or do I have to have ArcMap open to a specific .mxd in order to run the arcpy.Mapping stuff.
Tags (2)
0 Kudos
4 Replies
ChrisMathers
Occasional Contributor III
You do not need arcmap open to use arcpy. You can use any interactive python environment like IDLE or run a script that uses arcpy. To zoom and print you can either make a selection and zoom to selection before printing or you can directly edit the extent rectangle of the data frame object and print. Examples of both are in the arcpy.mapping help.
0 Kudos
MikePowell
New Contributor II
Sorry, that doesn't really answer my question. I know that I can run script outside of ArcMap ( I prefer to use PythonWin but I am wondering about when I am using the Arcpy.mapping and when I need to zoom in and print something. I am thinking that I need to have a .mxd open to perform those things.
0 Kudos
ChrisMathers
Occasional Contributor III
No. You can run any arcpy funciton outside of an arcmap session. This includes changes of extent and printing. Below will allow you to grab an mxd change the dataframe extent and export without ever opening arcmap.

import arcpy
mxd=arcpy.mapping.MapDocument(some mxd path)
dataframe=arcpy.mapping.ListDataFrames(mxd,{wildcards})[0]
newExtent = dataframe.extent
newExtent.XMin, newExtent.YMin = something, something
newExtent.XMax, newExtent.YMax = something, something
dataframe.extent=newExtent
arcpy.mapping.ExportToPDF (mxd,r'path and name to new pdf)
0 Kudos
MikePowell
New Contributor II
Ok, thank you. That was what I was looking for.
0 Kudos