Now that you have toolbar buttons and menu items, you may want one of those items to manipulate objects in your scenario, using either Connect or the STK Object Model. To do that, you need to create an instance of the AgStkObjectRoot.
For more information about using Connect or the STK Object Model, see Using Core Libraries.
[C#] |
---|
using AGI.STKObjects;
|
[Visual Basic .NET] |
---|
Imports AGI.STKObjects
|
[C#] |
---|
private AgStkObjectRoot m_root; |
[Visual Basic .NET] |
---|
Dim m_root As AgStkObjectRoot |
To make the private Object Model root available outside the MySampleUIPlugin class, add the following property to your UI Plugin. This isn't needed yet, but will be in a later section.
[C#] |
---|
public AgStkObjectRoot STKRoot { get { return m_root; } } |
[Visual Basic .NET] |
---|
Public Property STKRoot() As AgStkObjectRoot Get Return m_root End Get Set(ByVal value As AgStkObjectRoot) m_root = value End Set End Property |
[C#] |
---|
public void OnStartup (IAgUiPluginSite PluginSite) { m_psite = PluginSite; IAgUiApplication AgUiApp = m_psite.Application; m_root = AgUiApp.Personality2 as AgStkObjectRoot; } |
[Visual Basic .NET] |
---|
Public Sub OnStartup(PluginSite As AGI.Ui.Plugins.IAgUiPluginSite) Implements AGI.Ui.Plugins.IAgUiPlugin.OnStartup m_psite = PluginSite m_root = DirectCast(m_pSite.Application.Personality2, AgStkObjectRoot) End Sub |
Use the root to interact with STK. For this example, change the Exec function so that the toolbar button, instead of displaying a message box, creates a new scenario:
[C#] |
---|
public void Exec(string CommandName, IAgProgressTrackCancelM TrackCancel, IAgUiPluginCommandParameters Parameters) { if (string.Compare(CommandName, "MyCompany.MySampleUIPlugin.MyFirstCommand", true) == 0) { if (m_root.CurrentScenario == null) { m_root.NewScenario("MyNewScenario"); } } else if (string.Compare(CommandName, "MyCompany.MySampleUIPlugin.MySecondCommand", true) == 0) { MessageBox.Show(CommandName); } } |
[Visual Basic .NET] |
---|
Public Sub Exec(CommandName As String, TrackCancel As IAgProgressTrackCancel, Parameters As IAgUiPluginCommandParameters) Implements IAgUiPluginCommandTarget.Exec If (String.Compare(CommandName, "MyCompany.MySampleUIPlugin.MyFirstCommand", True) = 0) Then If (m_root.CurrentScenario Is Nothing) Then m_root.NewScenario("MyNewScenario") End If ElseIf (String.Compare(CommandName, "MyCompany.MySampleUIPlugin.MySecondCommand", True) = 0) Then MessageBox.Show(CommandName) End If End Sub |
See also: Isolate the Root
STK Programming Interface 11.0.1