' Title: Populates the elevation field for WatCad
' Topic: View, Tables
' Description: This script will populate the elevation field for the WatCad
' hydraulic model Junction points. A polygon-grid is needed which is created from contours
' using the spatial analyst tool'
' Requires: Must be associated with button click event.
' Self:
' Results
'***********************************************************************

'*** Read list of elevations points
theTable =av.GetProject.FindDoc("elevtbl.dbf")
theVTab = theTable.GetVTab
elvfld = theVTab.FindField("elev")
theTable.GetWin.Open

'*** Loops through each record in the list of elevations

for each record in theVTab
theElevNo = theVTab.ReturnValueString (elvfld, record)
'MsgBox.Info(theElevNo,"") '*** Remove comment for testing the list input
'exit '*** Remove comment when testing to prevent endless loop
'*********************************************************************

theIdxNo = theElevNo
theView = av.GetProject.FindDoc("View1")
theCtrTheme = theView.FindTheme("Grid-Demo2.shp") 'The poly-grid file name goes here

theDpy = theView.GetDisplay

if (theCtrTheme.IsActive.not) then
theCtrTheme.SetActive(true)
end
theVTabCtr = theCtrTheme.GetFTab

theBitMapCtr= theVTabCtr.GetSelection
selCtr = theBitMapCtr.GetNextSet (-1)
theField = theVTabCtr.FindField ("Elev")
theContour = theVTabCtr.ReturnValueString (theField, selCtr)

'For testing return varailble values 'MsgBox.Info (theIdxNo, "Run Time Message")
'MsgBox.Info (selCtr.AsString, "Run Time Message")
'MsgBox.Info (theField.AsString, "Run Time Message")
'MsgBox.Info (theContour, "Run Time Message")

aQstr = "[Elev] ="++theIdxNO

'MsgBox.Info (aQstr, "Run Time Message") 'For testing return varialble values

theVTabCtr.Query (aQstr, theBitMapCtr, #VTAB_SELTYPE_NEW)
theVTabCtr.SetSelection (theBitMapCtr)
'exit 'Remove comment when testing to prevent endless loop
'******************************************************************

if (theCtrTheme.IsActive) then
theCtrTheme.SetActive(false)
end

theView = av.GetProject.FindDoc("View1")
theNodeTheme = theView.FindTheme("Junction.shp")
theCtrTheme = theView.FindTheme("Grid-Demo2.shp")

theDpy = theView.GetDisplay

if (theNodeTheme.IsActive.not) then
theNodetheme.SetActive(true)
end

theVTabNode = theNodeTheme.GetFTab
theBitMapNode = theVTabNode.GetSelection
'*******************************************************************

distance = Units.Convert(1, #UNITS_LINEAR_FEET, #UNITS_LINEAR_FEET)

' select all Elevation polygon that ar within 1 feet of the selected point

theNodeTheme.SelectByTheme(theCtrTheme, #FTAB_RELTYPE_ISCOMPLETELYWITHIN, distance, #VTAB_SELTYPE_NEW)
theNodeFtab = theNodeTheme.GetFtab
theVTabNodeSel = theNodeFTab.GetSelection
< if ( theVTabNodeSel.IsEmpty) then
end

if ( theVTabNodeSel.IsEmpty.Not) then

theVTabNode.Calculate(theIdxNO, theVTabNode.FindField("Elevation"))
end
end
'********************************************************************