Good day,
I am new to python and am having the following problem. If I type the following code into the Python window in ArcMap:
import arcpy MXD=arcpy.mapping.mapdocument('CURRENT') dataframe = arcpy.mapping.ListDataFrames(MXD, "Layers")[0] dataframe.zoomToSelectedFeatures() arcpy.RefreshActiveView()
It works when run from the python window.
If I save it as a python script and add it to a modelbuilder model then try to run it from there it does not work.
This is the message that displays:
--------------------------------------------------------------------------------------------------------------------------------------
Executing (Zoom To Selected Feature): ZoomToSelected
Start Time: Wed Apr 06 14:30:39 2016
Running script ZoomToSelected...
Failed script ZoomToSelected...
Traceback (most recent call last):
File "X:\GIS\LUAM\Dev\Scripts\ZoomToSelected.py", line 2, in <module>
MXD=arcpy.mapping.mapdocument('C:\ESRIPress\GTKModelbuilder\Maps\EX06B.mxd') #get access to the current mxd
AttributeError: 'module' object has no attribute 'mapdocument'
Failed to execute (Zoom To Selected Feature).
Failed at Wed Apr 06 14:30:39 2016 (Elapsed Time: 0.08 seconds)
--------------------------------------------------------------------------------------------------------------------------------------
What am I doing wrong with trying to get this to work from modelbuidler?
Thanks,
Chris
Solved! Go to Solution.
check your casing. use:
arcpy.mapping.MapDocument
That's great Andrew. Thank you very much!