First off thanks Chris G. for your webinar on RASController recently good stuff. I got the book and am now trying to convert some of this to program R.
I have imported the COM object, and can open RAS and do a few basic things (very similar post as Chris Kelley’s post in C# Link here)
I cannot figure out how to get the Compute_CurrentPlan to work. Has anyone accomplished this in R?
Here is what I have so far…
# Ensure required packages are loaded
library(RDCOMClient)
# To see all COM objects
# Launch the Registry Editor.
# Click Start, and then click Run.
# In the Open box, type “regedit”, and then click OK.
# on the left expand HKEY_CLASSES_ROOT
# Look for RAS objects
# Open the RAS Controller
# Dim HRC As New HECRASController
HRC <- COMCreate("RAS503.HECRASController")
#RF <- COMCreate("RAS503.HECRASFlow")
#RG <- COMCreate("RAS503.HECRASGeometry")
#############################################################################
# Open a new project.
# Dim strRASProject As String
strRASProject = "C:\\Users\\m.modeler\\Documents\\HEC_RAS_EXAMPLES\\Example Projects\\1D Unsteady Flow Hydraulics\\Balde Eagle Creek\\BaldEagle.prj"
# HRC.Project_Open strRASProject
HRC$Project_Open(strRASProject)
HRC$CurrentGeomFile()
HRC$CurrentPlanFile()
HRC$CurrentSteadyFile()
HRC$CurrentUnsteadyFile()
HRC$CurrentProjectTitle()
HRC$Schematic_ReachCount()
# Open plan editor
HRC$Edit_PlanData()
# Run the HEC-RAS Project
# Dim lngMessages As Long
# Dim strMessages() As String
# HRC.Compute_CurrentPlan lngMessages, strMessages()
# ***This is where the issues occur***
lngMessages<-as.integer()
strMessages<-as.character()
HRC$Compute_ShowComputationWindow()
HRC$Compute_CurrentPlan(lngMessages, strMessages)
# ***This is where the issues occur***
# Get water surface elevations at Node 5
# Dim sngWSElev As Single
# sngWSElev = HRC.Output_NodeOutput(1, 1, 5, 0, 1, 2)
# riv = river ID
# rch = reach ID
# n = node ID
# updn = 0 for US, 1 for BR UP, 2 for BR DS,
# prof = profile ID
# nVar - variable ID
WSElev <- HRC$Output_NodeOutput(1, 1, 5, 0, 1, 2)
Q_Total <- HRC$Output_NodeOutput(1, 1, 5, 0, 1, 9)
#Plot
HRC$plotXS(1,1,5)
# MsgBox "The water surface elevation is " & sngWSElev & "."
print(paste0("The max water surface elevation is ", round(WSElev,2), "."))
print(paste0("The max Q total is ", round(Q_Total,2), "."))
#HRC.QuitRas
HRC$Project_Save()
HRC$Project_Close()
HRC$QuitRas
############################################
# Garbage Can
gc()
Any help would be great!
Thanks much,
Toby