Get the model open in the editor
Get the model of the active editor
The active editor (the editor that last had focus) can be obtained using the EditorPage.CurrentEditorView.Editor
property of the IWorkspaceWindow
object. You can get the model of the obtained IEditor
object using the Model
property.
public void GetModelInEditor(ICommandContext c, ICommandParams p)
{
IEditor editor = c.App.Window.EditorPage?.CurrentEditorView?.Editor;
if (editor == null) {
c.App.Window.UI.ShowMessageBox("Please display the editor before executing.");
return;
}
var model = editor.Model;
c.App.Output.WriteLine("Default", "Model to be edited: " + model.Name);
c.App.Output.WriteLine("Default", "View being edited: " + editor.ViewDefinition.DisplayName);
c.App.Output.WriteLine("Default", "Editor type: " + editor.EditorType);
}
info
The above sample code uses the following API, which has been experimentally implemented.
- IViewDefinition.DisplayName property
These APIs are not guaranteed for quality and are not listed in the API specifications. Use them at your own risk.
Get the main editor and sub-editor models
To get the main editor, use the MainEditorView
property of the IEditorPage
object, and to get the sub-editor, use the SubEditorView
property.
public void GetModelInMainSubEditors(ICommandContext c, ICommandParams p)
{
IEditorPage editorPage = c.App.Window.EditorPage;
//Get the two models open in the main editor and subeditor
var mainEditor = editorPage?.MainEditorView?.Editor;
var subEditor = editorPage?.SubEditorView?.Editor;
if ((mainEditor == null) || (subEditor == null))
{
c.App.Window.UI.ShowMessageBox("Please display models in the main editor and subeditor before executing.");
return;
}
c.App.Output.WriteLine("Default", "Model being edited in the main editor: " + mainEditor.Model.Name);
c.App.Output.WriteLine("Default", "Model being edited in the subeditor: " + subEditor.Model.Name);
}