Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

scrollbar

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 create show this functionality by creating a small script for our Volume model plugin that creates a runnable Volume model. 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 DeltaShell Delta Shell and go to the "the Toolbox" toolwindow panel.

Go to in the folder Scripts folder and , 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 the opened this scripting view:

Code Block
languagepy
# 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)
Info

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

Exercise results

Run the above indicated script (Ctrl CTRL + Enter).  After Once the script has finished running you should see something like this been run, the model will be fully configured, run and a view showing both the model input and output will be open:

 

scrollbar