I've been working tirelessly on trying to develop a code that will return an average slope for a selected area. I can build a model to give me the answer, but not as concise as I want it.The ideal code would be VBScript in which the user select an existing shapfile, runs the code, then a message box appears stating "Average Slope = xyz.xyz%".I have an elevation database on C:\geodata\elevation\ containing a 10m DEM and a slope file derived using spatial analyst of that DEM. The problem I see is using the extent/mask of a selected shapefile to calculate the mean pixel value of the slope raster.We use a code for finding shape acres (code listed below) and I've been trying to piggyback off of it with no avail. I've also tried using python but am having trouble making a scipt that will list a message box stating "Average Slope =". When I use this method I use zonal statistics and it provides a nice large table, but I only want the Mean value to be printed out as a message box.Thanks in advance for any advice anyone may have,- TysonPublic Sub ShapeAcres()
Dim pMxDoc As IMxDocument
Dim pArea As IArea
Dim pAcres As Double, pFeet As Double, pMeters As Double
Dim i As Integer, Looper As Integer
Dim pPoly As IFeature
Dim pMap As IMap
Dim pFSelection As IEnumFeature
Dim pActiveView As IActiveView
Dim pContentsView As IContentsView
Set pMxDoc = ThisDocument
Set pMap = pMxDoc.FocusMap
Set pActiveView = pMap
Set pContentsView = pMxDoc.CurrentContentsView
Set pFSelection = pMap.FeatureSelection
i = pMap.SelectionCount
'-- Make sure element is selected
If i = 0 Then
MsgBox "Please select one or more shapes"
Exit Sub
End If
Do Until Looper = i
Set pPoly = pFSelection.Next
Looper = Looper + 1
Set pArea = pPoly.Shape
pMeters = (pMeters + pArea.Area)
Loop
pFeet = pMeters * 10.76391042
pAcres = pFeet / 43560
MsgBox "Percent Slope = " & Format(pAcres, "##,###.0")
End Sub