Bundt Programmer's Guide
Bundt Programmer's Interface version 188.8.131.52
Load and Save Models
The following example shows how to save a model to disk, and then reload it.
Model persistence on disk is achieved through the FileModelPersister class.
Using this class, you can load and save models from/to disk.
To execute this code, you will need a reference to the ModellingEngine library.
//create a type model.
var tmo = ModelManager.CreateTypeModel("TypeTest", VersionInfo.OneZeroZeroZero);
//create a file persister for this model.
var fmpToSave = new FileModelPersister(tmo, "C:\\Temp\\MyModel.bundt-tm");
//save model to disk.
//create a new file persister to load the same model.
var fmpToLoad = new FileModelPersister("C:\\Temp\\MyModel.bundt-tm");
//load the mode from disk.
var tmoLoaded = fmpToLoad.LoadTypeModel();
In line 7, we create a FileModelPersister associated to the model that we want to save, tmo, as well as a filename.
Once we do this, the file model persister stays linked to this model for its lifetime.
In line 10, we save the model by calling SaveModel.
No parameters are needed as the file model persister maintains a link to the model.
In line 13, we create a new FileModelPersister with no associated model, as we want to load rather than save one.
At this point, this file model persister is not linked to any model.
Finally, in line 16 we load a type model by calling LoadTypeModel.
From this point on, the fmpToLoad file model persister is linked to the model it has loaded, so that we can use it in the future to save the model back to disk if necessary.
After running this code, the models referred to by tmo and tmoLoaded should be identical.
Contents distributed under a Creative Commons Attribution 4.0 International License
last updated on 08 October 2020