Try the following:
IMapBookmarks pMapBookmarks;
ISpatialBookmark pSpatialBookmark;
IEnumSpatialBookmark pBookmarkEnum;
IAOIBookmark pAOIBookmark;
pMapBookmarks = (IMapBookmarks)pMap;
pBookmarkEnum = pMapBookmarks.Bookmarks;
pBookmarkEnum.Reset();
pSpatialBookmark = pBookmarkEnum.Next();
pAOIBookmark = (IAOIBookmark)pSpatialBookmark;
IEnvelope pEnv = new EnvelopeClass();
while (pSpatialBookmark != null)
{
pEnv = pAOIBookmark.Location.Envelope; //Get the envelope from the bookmark
pSpatialBookmark = pBookmarkEnum.Next();
}
Once you have the envelope, you can create features in the output shapefile.
Here's the complete code in C#
public partial class Form1 : Form
{
DirectoryInfo StartDirectory;
List<string> MXDFileList = new List<string>();
string InitialPath = "C:\\NORMALTEMPLATE";
DialogResult dr;
IAoInitialize pESRILicense;
IMapDocument pMapDoc;
IMap pMap;
IEnumLayer pLayers;
ILayer pLayer;
IWorkspaceFactory pWSF;
IFeatureWorkspace pFeatureWS;
IWorkspace pWS;
IMapBookmarks pMapBookmarks;
ISpatialBookmark pSpatialBookmark;
IEnumSpatialBookmark pBookmarkEnum;
IAOIBookmark pAOIBookmark;
IEnvelope pEnv;
IPointCollection pPointCollection;
UID pUID = new UID();
IEditor pEditor;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
LicenseCheckout();
//parse directories for mxd files
ParseDirectory(InitialPath);
//parse each mxd file
ParseMXDForBookmarks();
}
private void LicenseCheckout()
{
try
{
int ESRILicenseCheckoutReturnCode;
bool ReturnResult;
//checkout ESRI license: ArcEditor
pESRILicense = new AoInitializeClass();
ESRILicenseCheckoutReturnCode = (int)pESRILicense.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcEditor);
ReturnResult = false;
switch (ESRILicenseCheckoutReturnCode)
{
case 10:
//esriLicenseAvailable
ReturnResult = true;
break;
case 20:
//esriLicenseNotLicensed
MessageBox.Show("You are not licensed to use the product!", "License Checkout Failure");
ReturnResult = false;
break;
case 30:
//esriLicenseUnavailable
MessageBox.Show("You are not licensed to use the product!", "License Checkout Failure");
ReturnResult = false;
break;
case 40:
//esriLicenseFailure
MessageBox.Show("There has been a licensing Failure!", "License Checkout Failure");
ReturnResult = false;
break;
case 50:
//esriLicenseAlreadyInitialized
MessageBox.Show("The Product license has already been initialized." +
"Initialization can only be performed once!", "License Checkout Failure");
ReturnResult = true;
break;
case 60:
//esriLicenseNotInitialized
MessageBox.Show("License not Initialized!");
ReturnResult = false;
break;
case 70:
//esriLicenseCheckedOut
ReturnResult = true;
break;
case 80:
//esriLicenseCheckedIn
MessageBox.Show("License ChekedIn successfully!");
ReturnResult = true;
break;
}
//return ReturnResult;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
//return false;
}
}
private void ParseDirectory(string StartPath)
{
StartDirectory = new DirectoryInfo(StartPath);
//get files in current directory
foreach (FileInfo files in StartDirectory.GetFiles("*.mxd"))
{
MXDFileList.Add(files.FullName);
}
//check for nested directories
if (StartDirectory.GetDirectories().Length > 0)
{
foreach (DirectoryInfo directories in StartDirectory.GetDirectories())
{
//recursion
ParseDirectory(directories.FullName);
}
}
}
private void ParseMXDForBookmarks()
{
try
{
IPolygon pPolygon;
IFeature pFeature;
IFeatureClass pFeatClass;
//initialize workspace for shapefile
pWSF = new ShapefileWorkspaceFactoryClass();
pWS = pWSF.OpenFromFile("C:\\NORMALTEMPLATE", (Int32)0);
pFeatureWS = (IFeatureWorkspace)pWS;
pFeatClass = pFeatureWS.OpenFeatureClass("test");
System.Object obj = new System.Object();
obj = Type.Missing;
for (int ListIndex = 0; ListIndex < MXDFileList.Count - 1; ListIndex++)
{
pMapDoc = new MapDocumentClass();
pMapDoc.Open(MXDFileList[ListIndex], null);
pMap = pMapDoc.get_Map(0);
pMapBookmarks = (IMapBookmarks)pMap;
pEnv = new EnvelopeClass();
pBookmarkEnum = pMapBookmarks.Bookmarks;
pBookmarkEnum.Reset();
pSpatialBookmark = pBookmarkEnum.Next();
pAOIBookmark = (IAOIBookmark)pSpatialBookmark;
while (pSpatialBookmark != null)
{
pEnv = pAOIBookmark.Location.Envelope; //Get the envelope from the bookmark
//create polygon out of this envelope
pPointCollection = new PolygonClass();
pPointCollection.AddPoint(pEnv.LowerLeft, ref obj, ref obj);
pPointCollection.AddPoint(pEnv.LowerRight, ref obj, ref obj);
pPointCollection.AddPoint(pEnv.UpperRight, ref obj, ref obj);
pPointCollection.AddPoint(pEnv.UpperLeft, ref obj, ref obj);
//close polygon
pPointCollection.AddPoint(pEnv.LowerLeft, ref obj, ref obj);
pPolygon = (IPolygon)pPointCollection;
pPolygon.Close();
pFeature = pFeatClass.CreateFeature();
pFeature.Shape = pPolygon;
pFeature.Store();
pSpatialBookmark = pBookmarkEnum.Next();
pEnv = null;
pPointCollection = null;
pPolygon = null;
pFeature = null;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
MessageBox.Show("Done!");
}
}