Remove data frame

380
1
06-03-2011 11:03 AM
DavidBarlow
New Contributor
Can somebody please tell me how to remove a data frame from an mxd from a stand alone program. I would prefer if it were in c# but VB is fine too. I am trying to use ImxDocument but keep getting the error telling me Object reference not set. Any help on this would be greatly appreciated!
0 Kudos
1 Reply
JohnNelson3
New Contributor III
public Boolean DeleteDataFrame(string strDataFrameName)
        {
            IMxDocument iMxDoc = (IMxDocument) ArcMap.Application.Document;
            ICommandBars iBar  = ArcMap.Application.Document.CommandBars;
            ICommandItem iItem;
            UID uUID = new UIDClass();
            try
            {
                for (int x = 0; iMxDoc.Maps.Count > x; x++)
                {
                    if (iMxDoc.Maps.Item.Name == strDataFrameName)
                    {
                        iMxDoc.CurrentContentsView.ContextItem = iMxDoc.Maps.Item;
                        uUID.Value = "{F42891B6-2C92-11D2-AE07-080009EC732A}";
                        uUID.SubType = 9;
                        iItem = iBar.Find(uUID,false,false);
                        if (iItem != null)
                        {
                            iItem.Execute();
                        }
                       
                        break;
                    }
                }
            }
            catch
            {
                return false;
            }
            return true;
        }
0 Kudos