OUtput_Nodeoutput only read out the first plan file in the loop

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

OUtput_Nodeoutput only read out the first plan file in the loop

hillwinner
Hi Chris,

I have the code to batch run RAS and read out the stage for a multi-plan project. I set a loop (Line 63), RAS runs for different plans (plan 5 and plan 6) but the Output_Nodeoutput always read out the first plan (plan 5 only and didn't read plan 6). Anyone can see anything I did wrong in the code?

Thanks

Shan

The code as Follows:
--------------------------------------------------------------

Sub BatchRunAndPostprocess()

    '--------------------------------------
   
    Dim strProjectFileName As String
    strProjectFileName = "C:\" & _
        "RAS_BatchRuns0915\runs" & _
        "\XS-1916\XS-1916.prj"
   
    'Open the HEC-RAS project
    Dim RC As New HECRASController
    RC.Project_Open strProjectFileName
   
    'Determine the number of plans
    Dim lngPlanCount As Long
    Dim strPlanNames() As String
    Dim blnIncludeOnlyPlansInDirectory As Boolean
    RC.Plan_Names lngPlanCount, strPlanNames(), blnIncludeOnlyPlansInDirectory
   
    'Determine the number of RS's in River 1 and Reach 1
    Dim lngNumRS As Long
    lngNumRS = RC.Geometry.nNode(1, 1)
   
    'Get River Stations
    Dim strRS() As String
    Dim strNodeType() As String
    RC.Geometry_GetNodes 1, 1, lngNumRS, strRS(), strNodeType()
   
    'Output the River Station ID and Plan Names
    '   to RiverStationID sheet.
    Dim i As Long, j As Long
    Dim blnSheetExists As Boolean
    For i = 1 To Sheets.Count
        If Sheets(i).Name = "RiverStationID" Then
            blnSheetExists = True
        End If
    Next i
    If blnSheetExists = False Then
        Sheets.Add
        ActiveSheet.Name = "RiverStationID"
    End If
    Sheets("RiverStationID").Select
   
    For i = 1 To lngNumRS
        Cells(i, 1).Value = i
        Cells(i, 2).Value = strRS(i)
        Cells(i, 3).Value = strNodeType(i)
    Next i
   
    'Cells(1, 4).Value = lngPlanCount
    For i = 1 To lngPlanCount
        Cells(i, 4).Value = i
        Cells(i, 5).Value = strPlanNames(i)
    Next i
    '----------------------------------------
    'Run HEC-RAS  and Postprocess by loop through
   
    Dim blnSetIt As Boolean
    Dim lngMessages As Long
    Dim strMessages() As String
    Dim blnDidItCompute As Boolean

    For iplan = 5 To 6 'lngPlanCount
   
    blnSetIt = RC.Plan_SetCurrent(strPlanNames(iplan))
    RC.Project_Save
    RC.Project_Open strProjectFileName
       
    blnDidItCompute = RC.Compute_CurrentPlan(lngMessages, strMessages())
   
    '----------------------------------------
    'Determine the number of profiles
    Dim lngNumProf As Long
    Dim strProfileName() As String
    RC.Output_GetProfiles lngNumProf, strProfileName()
   
    MsgBox "Current PlanName=" & strPlanNames(iplan) & " nProfile=" & lngNumProf
   
   
    'Get initial stages.  Uses profile number 2, since profile
    '   number 1 is the MaxWS profile. number 2 is 1st initial
    Dim sngMaxStage() As Single: ReDim sngMaxStage(1 To _
        lngNumRS)
    Dim lngNVar As Long
    lngNVar = 2 'Output ID # for W/S Elevation
    For i = 1 To lngNumRS
        Application.StatusBar = "Getting maximum stage " & _
            "for node ID " & i & "."
        sngMaxStage(i) = RC.Output_NodeOutput(1, 1, i, 0, 1, _
            lngNVar)
    Next i
       
   
    'First check to see if the worksheet "strPlanName"
    '   already exists.  If not, add a new sheet and name it.
    blnSheetExists = False
    For i = 1 To Sheets.Count
        If Sheets(i).Name = strPlanNames(iplan) Then
            blnSheetExists = True
        End If
    Next i
   
    'If "RASResults" does not exist as a sheet, we'll
    '   add it.
    If blnSheetExists = False Then
        Sheets.Add
        ActiveSheet.Name = strPlanNames(iplan)
    End If
    Sheets(strPlanNames(iplan)).Select
   
    'Clear all the data so that can construct a fresh table _
        of data.
    Cells.Select
    Cells.Delete
   
    'Give the first column header.
    Range("A1").Select
    ActiveCell.Value = "DateAndTime"
    For j = 2 To lngNumProf
        Cells(j, 1).Value = strProfileName(j)
    Next j

    'Go through each cross section and profile
    '   to assign value to 2-d array for selected RS
    Dim lngNumSelectedRS As Long
    lngNumSelectedRS = 7
   
    Dim lngSelectedRS() As Long: ReDim lngSelectedRS(1 To lngNumSelectedRS) As Long
    Dim sngTmpStage As Single
    Dim sngStage() As Single: ReDim sngStage(1 To _
        lngNumSelectedRS, 1 To lngNumProf)
    lngSelectedRS(1) = 228
    lngSelectedRS(2) = 221
    lngSelectedRS(3) = 189
    lngSelectedRS(4) = 152
    lngSelectedRS(5) = 130
    lngSelectedRS(6) = 109
    lngSelectedRS(7) = 7
    For i = 1 To lngNumSelectedRS
        Cells(1, i + 1) = strRS(lngSelectedRS(i))
        For j = 2 To lngNumProf
            Application.StatusBar = "Reading " & _
                "Plan " & strPlanNames(iplan) & _
                " River  Station " & i _
                & "of " & lngNumSelectedRS & ", " & _
                "Profile " & j & "."
            sngStage(i, j) = RC.Output_NodeOutput(1, 1, _
                lngSelectedRS(i), 0, j, 2)
            Cells(j, i + 1).Value = sngStage(i, j)
        Next j
    Next i
   
   
    'Finish
    Next iplan
    'MsgBox "Done!"
    Application.StatusBar = "Finished!"
    'RC.QuitRAS
   
End Sub

Reply | Threaded
Open this post in threaded view
|

Re: OUtput_Nodeoutput only read out the first plan file in the loop

Ski907
I came across this question while searching for a solution to my own problem. I was having trouble looping through already computed plans changing them with .PlanOutput_SetCurrent and .Plan_SetCurrent then extracting results using .Output_NodesOutput . It just seemed like the output file was not being updated. The solution was to change the plan, save it, close the project and then re-open it:

RC.Plan_SetCurrent (strPlanNames(j))
        RC.Project_Save
        RC.Project_Close
        RC.Project_Open strRASProject  


Hopefully this will save someone the time it took me to figure this out...
Reply | Threaded
Open this post in threaded view
|

Re: OUtput_Nodeoutput only read out the first plan file in the loop

Chris G.
Administrator
Thanks for posting!

Sent from my iPhone

On Jun 19, 2018, at 1:41 AM, Ski907 [via HEC-RAS Help] <[hidden email]> wrote:

I came across this question while searching for a solution to my own problem. I was having trouble looping through already computed plans changing them with .PlanOutput_SetCurrent and .Plan_SetCurrent then extracting results using .Output_NodesOutput . It just seemed like the output file was not being updated. The solution was to change the plan, save it, close the project and then re-open it:

RC.Plan_SetCurrent (strPlanNames(j))
        RC.Project_Save
        RC.Project_Close
        RC.Project_Open strRASProject  


Hopefully this will save someone the time it took me to figure this out...


If you reply to this email, your message will be added to the discussion below:
http://hec-ras-help.1091112.n5.nabble.com/OUtput-Nodeoutput-only-read-out-the-first-plan-file-in-the-loop-tp3151p5781.html
To start a new topic under HECRAS Controller, email [hidden email]
To unsubscribe from HECRAS Controller, click here.
NAML
Chris G.
@RASModel
www.therassolution.com
Reply | Threaded
Open this post in threaded view
|

Re: OUtput_Nodeoutput only read out the first plan file in the loop

Sup97031
In reply to this post by Ski907
Thanks Ski901! I just ran into this issue with version 5.0.4 of the RAS Controller and your method to save and re-open worked.