dsldsl-tools

DSL Tools: Create a new Diagram in custom code


I am using DSL Tools for Visual Studio 2005.

I have a DSL where at a certain point I would like to create a new Diagram using custom code.

So far, I was able to create a new Diagram by overwriting the current, already opened diagram. Code follows:

FEGeneratorDiagram diag = new FEGeneratorDiagram(ThisElem.Store);
diag.Associate(ThisElem);
FEGeneratorDiagram currentDiag = (FEGeneratorDiagram)ThisElem.Store.ElementDirectory.FindElements<FEGeneratorDiagram>(false)[0];
currentDiag = diag;

But, what I would really like to do would be,

to create a new DSL document with a new instance FEGeneratorDiagram and then keep on my logic of adding elements and setting properties.

Any help?


Solution

  • //Create a Store
    Type[] modelTypes = new Type[] { typeof(CoreDesignSurfaceDomainModel), typeof(FEGeneratorDomainModel) };
    Store store = new Store(modelTypes);
    RootElement root;
    using (Transaction t =
    store.TransactionManager.BeginTransaction("Create Elements"))
    {
        root = FEGeneratorSerializationHelper.Instance.LoadModel(store, diagramPath, null, null);
        t.Commit();
    }
    //Do whatever custom things you want!
    
    SerializationResult result = new SerializationResult();
    //Save the file
    FEGeneratorSerializationHelper.Instance.SaveModel(result, root, diagramPath);