Pages

Monday, January 26, 2015

HECRASController VBA Code-Companion to “Breaking the HEC-RAS Code”

Written by Christopher Goodell, P.E., D.WRE  |  WEST Consultants
Copyright © The RAS Solution 2015.  All rights reserved.

There has been a lot of demand from new owners of the book “Breaking the HEC-RAS Code” for example code in VBA form.  So…here it is!  Aside from the obvious fact that you wont have to re-type code from the book into your own Excel VBA modules, this Excel Workbook provides the benefit of seeing how each and every procedure in the HECRASController works.

 image
That’s right, every subroutine, and every function are documented in this workbook, along with example code from a wide range of HEC-RAS automation procedures and some code snippets for error catching and string manipulation-very important when reading/writing HEC-RAS input files.  In total, there are over 150 procedures and over 8000 lines of code for you to use for help while you create your own HEC-RAS automation projects.


Each procedure from the HECRASController is demonstrated in either a subroutine or function in this Excel Workbook.  Each demonstration provides up-front commentary including the procedure's name, what it does, cautions and pitfalls to look out for, as well as what standard HEC data set it was tested with (i.e. Bald Eagle Creek, Beaver Creek, etc.). 


image
There’s also commentary all throughout each demonstration so that you’ll know exactly what each block of code does.  

The HECRASController VBA Code Excel Workbook will make a valuable companion to “Breaking the HEC-RAS Code”.  Every bit of code presented in the book is available in digital form in the Excel Workbook.  The HECRASController VBA Code is optimized for Version 5.0 of HEC-RAS. It will work right now with the current beta release, and will work with the official version when it is released.  

The HECRASController VBA Code Excel Workbook is available here:



11 comments:

  1. Seriously? I was fine paying $85 for the book, but now you're charging $60 for an Excel spreadsheet with some macros?

    ReplyDelete
    Replies
    1. That's quite the comment "Anonymous". First of all, thank you for buying the book, but no one made you buy it and no one is making you buy the HECRASController Code workbook. If you don't think there is value in it, don't buy it. Second, it sounds like you don't have an appreciation for how much work was spent putting it together. It's not a "few" macros. It's every HECRASController procedure plus many other examples. Over 150 in all. I'd be happy to talk with you more on the concept of intellectual property and basic principles of economics if you like. Otherwise, please make your own Excel workbook coding and documenting every single HEC-RAS controller and then give it away without any compensation for the work you put into it. Good luck.

      Delete
    2. Sorry, I get it, and I really do appreciate the work you've done here. It's just frustrating that these major features have been undocumented (at least publicly) for so long. I'm glad there's finally something available.

      Delete
    3. No worries. And I understand the frustration too. That's the primary reason I began this project 5 years ago.

      Delete
  2. Hi Chris, we have an Hec-ras model with all cross-sections. We would like to add in bridges and culverts (a great number of them). Can we use HECRAScontroller to insert bridges and culverts by write a code? if so, do you have examples in your companion excel workbook for a quick start?

    ReplyDelete
    Replies
    1. Yes, you can use the Edit_AddBC procedure. However, for RAS to save the newly created Bridge or culvert, you have to make some kind of edit to it inside of HEC-RAS. Therefore, it might be easier just to write code that automatically inserts your bridges and culverts directly into the Geometry input text file. Chapter 4 in “Breaking the HEC-RAS Code” discusses in detail how to write to the geometry text file. Also, the Geometry Input File Keys presented in Appendix B will be of tremendous help to you. I don’t have sample code on hand that does this, but it shouldn’t be difficult to write. Write code to progress through the geometry input file. When you get between two existing river stations where you want to insert a bridge, have the code construct the bridge/culvert input structure at that location in the text file.

      Delete
  3. Hey Chris, I ordered the book and am excited to get working with it. My big question is, does the controller allow me to iterate over various Manning-n values, or other numeric settings, or different XS interpolation distances? These are the typical attributes that would be used in a sensitivity analysis of a 1D model.

    Are the codes to do those things, and export the results in a usable form, in these example codes?

    It might be helpful to see a TOC to decide if it's worth it to buy the VBA codes.

    Thanks!

    ReplyDelete
    Replies
    1. Hi Ari-

      Thanks for buying my book. I hope you find it helpful. The controller API library is good for performing tasks like opening/closing RAS, running computations, and extracting output. I've found that changing geometry is typically easier to do by rewriting the geometry file each iteration. Chapter 4 of the book explains how to do this. Also, Appendix B will be helpful as it documents all of the input parameter keys found in the geometry text file. Good luck!

      As for the VBA code workbook, there's no TOC, but every procedure in the HECRASController API is documented with useable code. You can easily copy and paste that code into your project. Plus all of the example projects in the book are available in the VBA Code workbook for you to use and/or amend for your project. I think you'll find it very useful, especially if you are somewhat new to VBA programming.

      Thanks again-
      Chris

      Delete
  4. Hi Chris

    I purchased your book and it was very useful for me to automate HEC-RAS to generate inundation pattern of some river sections in Sri Lanka. However I am not using VBA but C# in doing that.

    However I have following tasks yet to acomplish;
    1. Generate inundation pattern in GIS map forms from hec ras 4.3 Geometry data. Since I have fair skill in programming, can you give some some guidence?
    2. For some areas there is no high accuracy DEM's. Can you suggest any open source Global resource for that?(with an indication of hight accuracy?)

    Ragards
    Prasanna Lenadora

    ReplyDelete
    Replies
    1. Thanks for buying the book. As for your questions,
      1. I would suggest you explore reading from the HDF forms to build rasters for generating new nindation patterns in GIS. There are many libraries out there that read from HDF files. I bet there’s one for C#.
      2. I’m not sure for Sri Lanka. Anything for free on the web is likely to be pretty coarse resolution. The NASA SRTM data is world wide and seems to be decent. But not great.

      Delete
  5. Hi Chris, My group in UCONN bought your book recently. We are trying to see how to use VB or C# to automatically generate variable 2D mesh. The major process is But we definitely met a few errors if one grid has more than 8 neighours. In the GUI, it is easy to remove by clicking the error polygon and dividing them into two. But which function can help in VB.net or C#? I did not find any info.

    Thanks

    ReplyDelete

Note: Only a member of this blog may post a comment.