Skip to main content

Show diagram

This is an example of switching the view of the active model editor to the ER diagram.

public void ShowDiagram(ICommandContext c, ICommandParams p) 
{
IEditorView editorView = c.App.Window.EditorPage?.CurrentEditorView;
if (editorView == null) {
c.App.Window.UI.ShowMessageBox("Please display the model editor before executing.");
return;
}

//If there is an ER diagram among the view that can be switched, display it.
IEditorDefCollection views = editorView.ViewDefinitions;
foreach (var view in views)
{
if (view.Type.Equals("ERDiagram")) {
editorView.SelectViewDefinition(view);
break;
}
}

//If the ER diagram cannot be displayed, display a message.
if (! editorView.Editor.EditorType.Equals("ERDiagram")) {
c.App.Window.UI.ShowMessageBox("There are no ER diagrams to switch to.");
}
}