http://blogs.clariusconsulting.net/pga

Pablo Galiano's Blog

Go Back to
pga′s Latest post

How do I select a DSL shape via API

My second How do I is up.

Scenario

Let’s say that we want to synchronize the DSL model explorer with the DSL designer. Somehow we need to select a particular shape every time a node in the tree is selected. The focus of this How do I tackles this scenario.

 

Interfaces and classes needed

 

Code snippet

    public void SelectShape(ModelElement modelElement)

    {

        ShapeElement modelElementShape = PresentationViewsSubject.GetPresentation(modelElement).FirstOrDefault() as ShapeElement;

 

        Diagram diagram = modelElement.Store.ElementDirectory.AllElements.OfType<Diagram>().FirstOrDefault();

        DiagramItem diagramItem = new DiagramItem(modelElementShape);

        diagram.ActiveDiagramView.Selection.Set(diagramItem);

    }

Assemblies needed

  • Microsoft.VisualStudio.Modeling.Sdk
  • Microsoft.VisualStudio.Modeling.Sdk.Diagrams

 

Stay tuned,

Pablo

Comments