Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Where is the tool for this? Have looked around and the closet thing i can find is Toolbox's Grid/Strip Map Index tools under Data Drive Pages. I just want to be able to create a single polygon rectangle shp file based on the data frame (in layout view) for any given scale / page setup.

share|improve this question
are you using the mapbook tool, or just wanting to create a shp polygon for one layout view? – artwork21 Aug 15 '11 at 15:54
for just one layout view – sirgeo Aug 15 '11 at 16:24
If this is for an inset map, check out the extent indicator option in the data frame properties. If it is for other reasons, I would just write a python script for it. – MLowry Aug 15 '11 at 18:05
How much time would it take to write a python script for this MLowry? It is for taking raster image exports from ArcGIS to AutoCad and will be needed many times in the future. I just downloaded VS Express and will give Kirk's C# a shot but working with this stuff is way beyond my knowledge base. – sirgeo Aug 15 '11 at 20:23
up vote 9 down vote accepted

I created a tool to do this via a Toolbox in ArcGIS 10. It might be easier to use than scripting. You can download it here. Just copy your mxd(s) into a folder and run the tool on that folder. It will create a shapefile containing all the main extents of each mxd in that folder.

share|improve this answer
Brilliant npeihl, works like a charm. Thank you. – sirgeo Aug 16 '11 at 12:51

This c# code could be used to build an add-in for Arcmap.

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Windows.Forms;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.ArcMapUI;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.Geodatabase;

namespace MainToolsAddin
    public class Extent2ShapefileButton : ESRI.ArcGIS.Desktop.AddIns.Button
        public Extent2ShapefileButton()

        protected override void OnClick()
                var polygon = GetExtentPolygon(ArcMap.Document.FocusMap);
                //IGraphicsContainer gc = ArcMap.Document.FocusMap as IGraphicsContainer;
                //var element = new PolygonElementClass() as IElement;
                //element.Geometry = polygon;
                //((IFillShapeElement)element).Symbol = ((IDocumentDefaultSymbols)ArcMap.Document).FillSymbol;
                WritePolygon(@"C:\projects\forums\extents.shp", polygon);
            catch (Exception ex)

        protected override void OnUpdate()

        private void WritePolygon(string shpFilePath, IGeometry geom)
            var featClass = OpenShapeFile(shpFilePath);
            if (featClass == null)
                featClass = CreateShapeFile(shpFilePath, geom);
            IFeature feat = featClass.CreateFeature();
            feat.Shape = geom;
        private IFeatureClass CreateShapeFile(string shpFilepath, IGeometry geom)
            System.IO.FileInfo fi = new FileInfo(shpFilepath);
            var wsf = Activator.CreateInstance(Type.GetTypeFromProgID("esriDataSourcesFile.ShapefileWorkspaceFactory")) as IWorkspaceFactory;
            var fws = wsf.OpenFromFile(fi.DirectoryName, 0) as IFeatureWorkspace;
            IFieldsEdit flds = new FieldsClass();
            flds.AddField(MakeField("ObjectID", esriFieldType.esriFieldTypeOID,0));
            IGeometryDefEdit geomDef = new GeometryDefClass();
            geomDef.GeometryType_2 = geom.GeometryType;
            geomDef.SpatialReference_2 = geom.SpatialReference;
            var shpField = MakeField("Shape", esriFieldType.esriFieldTypeGeometry, 0) as IFieldEdit;
            shpField.GeometryDef_2 = geomDef;
            flds.AddField(MakeField("Name", esriFieldType.esriFieldTypeString, 16));
            string fcName = fi.Name;
            if (fcName.ToUpper().EndsWith(".SHP"))
                fcName = fcName.Substring(0, fcName.LastIndexOf("."));

            var fc = fws.CreateFeatureClass(fcName, flds, null, null, esriFeatureType.esriFTSimple, "Shape", "");
            return fc;

        private IField MakeField(string name, esriFieldType fType, int length)
            IFieldEdit fld = new FieldClass();
            fld.Name_2 = name;
            fld.Type_2 = fType;
            if (length > 0 && fType == esriFieldType.esriFieldTypeString)
                fld.Length_2 = length;
            return fld;

        private IFeatureClass OpenShapeFile(string shpFilepath)
            var wsf = Activator.CreateInstance(Type.GetTypeFromProgID("esriDataSourcesFile.ShapefileWorkspaceFactory")) as IWorkspaceFactory;

            System.IO.FileInfo fi = new FileInfo(shpFilepath);
            string name = fi.Name.ToUpper().EndsWith(".SHP") ? fi.Name.Substring(0, fi.Name.LastIndexOf(".")) : fi.Name;
            string fileName = String.Format("{0}.shp", name);
            if (File.Exists(System.IO.Path.Combine(fi.DirectoryName,fileName)))
                var fws = wsf.OpenFromFile(fi.DirectoryName, 0) as IFeatureWorkspace;
                return fws.OpenFeatureClass(name);
                return null;

        private IPolygon GetExtentPolygon(IMap map)
            // A polygon is returned since the dataframe might be rotated
            var grphCont = ArcMap.Document.PageLayout as IGraphicsContainer;
            var mapFrame = grphCont.FindFrame(map) as IMapFrame;
            var av = map as IActiveView;
            var extent = mapFrame.MapBounds.Envelope;
            ISegmentCollection sc = new PolygonClass() as ISegmentCollection;

            var center = ((IArea)extent).Centroid;
            var angle = -(av.ScreenDisplay.DisplayTransformation.Rotation / 180.0 * Math.PI);
            ((ITransform2D)sc).Rotate(center, angle);
            return (IPolygon)sc;                        

When you create a new add-in project with Visual Studio, you should see some options like this. I'm not sure if it works with Visual Studio Express, or whether the ArcObjects SDK needs to be installed.

enter image description here

share|improve this answer
Thanks Kirk, this will be my first attempt using the new ArcGIS Add-Ins Wizard. First question, it says "1. Start Visual Studio" Where is Visual Studio? a download? I am a programming dunce so please explain gently. – sirgeo Aug 15 '11 at 19:04
I've never used it, but you should be able to download the free ("Express") version of Visual Studio here. This link says "... due to limitations in the Express versions of Visual Studio, not all features of the framework are supported in the Express editions." They don't say which features though. – Kirk Kuykendall Aug 15 '11 at 19:10
okay, i downloaded the 700mb VS Express and now it is installing 3.4gb of stuff... what else is ArcGIS Add-Ins Wizard going to require? – sirgeo Aug 15 '11 at 20:00
I'm not certain, but you might need to install the "ArcObjects SDK for the Microsoft framework" too. I have it installed on my machine. Have never tried to create an Add-in without it though. – Kirk Kuykendall Aug 15 '11 at 20:21
well i got to step 2 "Click File, select New, and click Project. The New Project dialog box opens." but step 3 "Under Project types, expand the Visual Basic or Visual C# project node, expand the ArcGIS node, and click Desktop Add-Ins." makes no sense... screen shot here: – sirgeo Aug 15 '11 at 20:40

You could use the Create Dataframe Footprint tool/code. You will either have to request a VBA license from ESRI or create a Visual Studio (VS) ICommand button to execute the code. The current code is setup for VBA use, however it could be setup in VS Express.

share|improve this answer
holy cannoli that's alot of code for such a simple task... – sirgeo Aug 15 '11 at 16:55

If you only need to do it once, you can find the extents in the Data Frame properties window. Then you can create a new shapefile, add a new feature, right-click and choose to manually enter the coordinates corresponding to the corners.

Otherwise go with the script from @artwork21.

share|improve this answer

I see this NOAA portal with a program.
Script - extents to shapefile
I know I have seen that somewhere. Still looking.
Here are a couple of ddp tools on the resources center.

share|improve this answer
i used to use that one in 9.3 For some reason it does not work in 10 – sirgeo Aug 15 '11 at 16:13

Works in 10.3

Load the add-in, then customize a tool bar (or create a new one) and add it. It's called Clip Data Frame

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.