Bundt Programmer's Guide · Bundt Programmer's Interface version

Execute a Script on a Model

The following example shows how to execute a script on a model.

Please see the Bundt Scripting Reference for additional details on the Bundt Scripting Language.

Scripting in Bundt is handled by the Scripting library, so you will need a reference to this in addition to ModellingEngine.

using Incipit.Bundt.ModellingEngine;
using Incipit.Bundt.Scripting;

//load a type model.
var tmo = new FileModelPersister("C:\\Temp\\MyModel.bundt-tm").LoadTypeModel();

//create a scripting session and attach the model to work with.
var ss = ScriptingEngine.CreateSession();

//run a short script.
bool bSuccess = ss.RunScriptFromText("with model MyModel; create class Cat;");
    Console.WriteLine($"{ss.Messages.Count} messages.");

//run a script from a file.

In line 5, we load a type model.

In lines 8-9, we create a scripting session by calling ScriptingEngine.CreateSession. Then, we attach the previously loaded model to this session by calling AttachModel.

In lines 12-16, we execute a brief script by calling RunScriptFromText and passing the script code as an argument. Then, we write out the number of error messages if the execution was not successful. Note that the Messages collection contains useful information to diagnose what was wrong with your script code.

In line 19, we execute a script that is stored on a file by calling RunScriptFromFile and passing the file name as an argument.

Contents distributed under a Creative Commons Attribution 4.0 International License · About · Terms of Use · Contact Us · last updated on 08 October 2020