Skip to main content

Accessing editor information

To access elements (shapes, etc.) in the currently displayed editor, obtain an IEditor object using the Editor property of the IEditorView object. You can access elements in the editor using the IEditor properties and methods.

The following are some ways to use the IEditor properties and methods.

Below is an example of changing the color of the shapes in the ER diagram displayed in the main editor.

public void SetShapeColor(ICommandContext c, ICommandParams p) 
{
//Get the diagram displayed in the main editor
IEditorView mainEditorView = c.App.Window.EditorPage?.MainEditorView;
IDiagram diagram = mainEditorView?.Editor as IDiagram;
if(diagram == null)
{
//If the diagram is not displayed, end the process
c.App.Output.WriteLine("sample", "Diagram is not displayed.");
return;
}

//Get the node displayed on the diagram
INode node = diagram.Nodes.FirstOrDefault();
if(node ​​== null)
{
//If the node is not displayed, end the process
c.App.Output.WriteLine("sample", "Node is not displayed.");
return;
}

//Get the node style and change the color
IShapeStyle style = node.Style;
style.BackColor = "Red"; //Change background color to default
style.ForeColor = "#ffffff"; //Change foreground color in code
}

If you are displaying the comparison editor in the model editor, you can get the comparison editor using the DiffEditor property of IEditorView.

public void GetDiffEditor(ICommandContext c, ICommandParams p) 
{
//Get the difference comparison editor displayed in the main editor.
IEditorView mainEditorView = c.App.Window.EditorPage?.MainEditorView;
IEditor diffEditor = mainEditorView?.DiffEditor;
if(diffEditor == null)
{
//End processing if the difference comparison editor is not displayed.
c.App.Output.WriteLine("sample", "Diff comparison editor is not displayed.");
return;
}

c.App.Output.WriteLine("sample", $"The model displayed in the difference comparison editor is {diffEditor.Model.Name}.");
}