Skip to main content

Get view definition

Get all editor definitions

To get all editor definitions defined in a profile, use the Editors property of the IViewDefinitions object.

public void FindEditorDefByClass(ICommandContext c, ICommandParams p) 
{
//Get view definitions
IViewDefinitions viewDefinitions = c.App.Workspace.CurrentProject.Profile.ViewDefinitions;

//Get all editor definitions
IEditorDefCollection editorDefs = viewDefinitions.Editors;

//Output all editor definitions
foreach (var editorDef in editorDefs)
{
c.App.Output.WriteLine("sample", $"EditorDefinition: {editorDef.DisplayName}");
}
}
info

The above sample code uses the following APIs, which have been experimentally implemented.

  • IEditorDef.DisplayName property

These APIs are not guaranteed to be of high quality and are not listed in the API specifications. If you use them, you do so at your own risk.

Get the editor definition for a class

To get the view definition for an editor defined in a class, use the FindEditorDefByClass method of the IViewDefinitions object.

public void FindEditorDefByClass(ICommandContext c, ICommandParams p) 
{
//Get the view definitions
IViewDefinitions viewDefinitions = c.App.Workspace.CurrentProject.Profile.ViewDefinitions;

//Get the class of the currently displayed model
IClass cls = c.App.Workspace.CurrentModel.Metaclass;

//Get the editors defined for the class
IEditorDefCollection editorDefs = viewDefinitions.FindEditorDefByClass(cls);

//Print the editor definitions
c.App.Output.WriteLine("sample", $"Class: {cls.DisplayName}");
foreach (var editorDef in editorDefs)
{
c.App.Output.WriteLine("sample", $" EditorDefinition: {editorDef.DisplayName}");
}
}
info

The above sample code uses the following APIs, which have been experimentally implemented.

  • IEditorDef.DisplayName property

These APIs are not guaranteed to be of high quality and are not listed in the API specifications. Use them at your own risk.

Get a list of editor element definitions

To get a list of editor element definitions, use the Elements property of the IEditorDef object.

public void IEditorDefElements(ICommandContext c, ICommandParams p) 
{
//Get the editor definition for the currently displayed editor
IEditorDef editorDef = c.App.Workspace.CurrentEditor.EditorDefinition;

//Get a list of editor element definitions
IElementDefCollection elementDefs = editorDef.Elements;

//Output the editor element definitions
c.App.Output.WriteLine("sample", $"EditorDefinition: {editorDef.DisplayName}");
foreach (var elementDef in elementDefs)
{
c.App.Output.WriteLine("sample", $" Element: {elementDef.DisplayName}");
c.App.Output.WriteLine("sample", $" Type: {elementDef.Type}");
}
}
info

The above sample code uses the following APIs, which have been experimentally implemented.

  • IEditorDef.DisplayName property
  • IElementDef.DisplayName property

These APIs are not guaranteed to be of high quality and are not listed in the API specifications. Use them at your own risk.

Find an editor element definition that corresponds to a class from an editor definition

You can find an editor element definition that corresponds to a specific class from a specified editor definition by using the FindElementDefByClass method of the IViewDefinitions object. For example, you can easily obtain the registration target of a callback function for Conditional formatting changes in the diagram view.

tip

For more information on how to use conditional formatting changes in the diagram view, see here.

public void IEditorDefElements(ICommandContext c, ICommandParams p) 
{
//Get the editor definition for the currently displayed editor
IEditorDef editorDef = c.App.Workspace.CurrentEditor.EditorDefinition;

IProfile profile = c.App.Workspace.CurrentProject.Profile;

//Specify the class
IClass cls = profile.Metamodels.GetClass("SomeClass");

//Get a list of editor element definitions corresponding to the specified class
IEnumerable<IElementDef> elementDefs = profile.ViewDefinitions.FindElementDefByClass(editorDef, cls);

//Output the editor element definition
c.App.Output.WriteLine("sample", $"EditorDefinition: {editorDef.DisplayName}");
foreach (var elementDef in elementDefs)
{
c.App.Output.WriteLine("sample", $" Element: {elementDef.DisplayName}");
c.App.Output.WriteLine("sample", $" Type: {elementDef.Type}");
}
}
info

The above sample code uses the following APIs, which have been experimentally implemented.

  • IEditorDef.DisplayName property
  • IElementDef.DisplayName property

These APIs are not guaranteed to be of high quality and are not listed in the API specifications. If you use them, you do so at your own risk.