Welcome to the RAS Solution Forums HECRAS Controller Running API in python – RAS is closed before it has time to run in loop

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #16182
    Kathleen H.
    Participant

    Within a python script I am editing the unsteady flow file, calling the RAS api, and then exporting the results of interest, but my RAS window is being closed before it has time to complete a simulation. I have included the portion of code of interest below.

    import win32com.client
    hec = win32com.client.Dispatch(‘RAS630.HECRASController’)
    hec.Project_Open(r”file path”)
    hec.ShowRAS()
    hec.Compute_CurrentPlan()
    hec.QuitRAS()

    I have come across the option to use time.sleep(# seconds), which works, but I anticipate some of my runs to take longer. Has anyone come across this and found a way to resolve it?

    #16204
    Kathleen H.
    Participant

    For those who run into the same issue – I resolved this by defining the three arguments needed in Compute_CurrentPlan(). The third argument is Blocking Mode and when set to True, the code waits for the RAS computation to complete before moving to the next line of code.

    So use:
    hec.Compute_CurrentPlan(None, None, True)

    I checked what was being seen by assigning a variable and then printing.
    test = hec.Compute_CurrentPlan(None, None, True)
    Print(test)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.