Exercise outline

Both Delta Shell and the plug-ins implemented for this framework, are automatically accessible through scripting in the IronPython language. The goal of this exercise is to show this functionality by creating a small script for our Volume model plugin. This script will create a new Volume model and configure it. It will also run it and open a view to show the results.

Create a script in the Delta Shell toolbox

Run Delta Shell and go to the Toolbox panel.

in the folder Scripts, create a new script (right click on folder | Add new script) named VolumeModelScript.
A new view with an ironPython editor will be automatically opened. Add the following code in this scripting view:

# import standard scripting library
from Libraries.StandardFunctions import *

# import our model
from DeltaShell.Plugins.VolumeModel.Models import VolumeModel

# import some DeltaShell (C#) libraries
from NetTopologySuite.Extensions.Features import Feature
from NetTopologySuite.Extensions.Geometries import GeometryHelper

# import .Net library
from System import DateTime

# create an instance of our model and set the name
model = VolumeModel()
model.Name = "My test model"

# Generate Precipitation data
startDate = DateTime.Now

for i in range(0,100):
    currentDateTime = startDate.AddHours(i)
    model.Precipitation[currentDateTime] = i * 1.0 # convert i to double

# Generate drainagebasin
for i in range(0,10):
    newFeature = Feature()

    offset = i * 100
    newFeature.Geometry = GeometryHelper.GetRectangle(0 + offset,0 + offset,100+ offset,100+ offset)

    model.Basin.Catchments.Add(newFeature)

# Add model to project
AddToProject(model)

# Run the model
RunModel(model, True)

# Open a view for the model
OpenView(model)

The comments in the code should explain the different parts of the script.

Exercise results

Run the above indicated script (CTRL + Enter).  Once the script has been run, the model will be fully configured, run and a view showing both the model input and output will be open:

 

  • No labels