Is This Content Helpful?
How can we make this better? Please provide as much detail as possible.
Instructions provided describe how to create a custom button in ArcMap that returns the area of a selected polygon graphic.
Note: This code is not designed to find the area of polygon features in shapefiles, feature classes, or coverages. This code only determines the area of selected polygon graphic elements in a map document, such as those created with the graphic tools on the Drawing toolbar.
Note: For more information on creating a UIControl, see the ArcGIS Desktop Help topic: Creating custom commands with VBA and UI Controls
Dim pApp As IApplication Set pApp = Application '-- Get the map document Dim pDoc As IMxDocument Set pDoc = ThisDocument '-- Get the graphics container for the active view Dim pAv As IActiveView Set pAv = pDoc.ActiveView Dim pGc As IGraphicsContainerSelect Set pGc = pAv.GraphicsContainer '--Make sure a graphic element is selected If pGc.ElementSelectionCount = 0 Then MsgBox "Please select a graphic element" Exit Sub End If '-- Make sure only one element is selected Dim pElem As IElement If pGc.ElementSelectionCount > 1 Then MsgBox "Only one element can be selected" Exit Sub End If '-- Get the area for the selected element Dim pPoly As IPolygon Dim pArea As IArea Set pElem = pGc.SelectedElement(0) If TypeOf pElem.Geometry Is IPolygon Then Set pArea = pElem.Geometry '-- Send the area to the status bar pApp.StatusBar.Message(0) = "Element Area : " & pArea.Area '-- or a message box MsgBox "Element Area: " & pArea.Area End If