STK X Send comments on this topic.
ExecuteCommand Method (AgSTKXApplication)
See Also  Example
Connect command to execute. For instance: "New / Scenario Scenario1".

Windows & Linux


Send a connect command to STK X.


[Visual Basic .NET]
Public Function ExecuteCommand( _
   ByVal Command As String _
) As IAgExecCmdResult

public IAgExecCmdResult ExecuteCommand(
string Command

[Managed C++]
public: IAgExecCmdResult^ ExecuteCommand(
String __gc ^ Command

public IAgExecCmdResult executeCommand(
String Command

[Unmanaged C++]
public: HRESULT ExecuteCommand(
BSTR Command,
IAgExecCmdResult ** ReturnValue


Connect command to execute. For instance: "New / Scenario Scenario1".

Return Type

If the command succeeds, a collection of strings (AgExecCmdResult object) is returned.

If the command fails, an automation exception is raised (error code: 0x80040002, text: "Command Failed").


Following is a brief description of the basic format for data sent to and from Connect. Syntax for each command is explained briefly. Syntax specifies the order in which you must generate a Connect command as well as any parameters and switches associated with the command.

    Input Command Format to Connect

Commands sent to Connect use the following format:


NOTE: Although the field isn't case sensitive, the is. may or may not be case sensitive.


Syntax Description
The name of a particular command (e.g., Load).
The object (e.g., Scenario/stkDemo/Satellite/Shuttle) to which the directs action.
[] fields modify a and may or may not be required. Please refer to the format of the individual commands for additional information.

NOTE: Since only one scenario can be open at any given time in STK, you can substitute the scenario name with a wildcard (*) so that the is Scenario/* or just *. For example, you could type Scenario/* for Scenario/stkDemo, where * refers to the scenario loaded.


If the command succeeds, the return value contains the list of strings.

If the command fails, a COM exception is raised (error code: 0x80040002, text: "Command Failed"). To implement error processing you need to handle this exception. This varies from language to language:

  • in the .NET languages you need to catch an exception of type System.Runtime.InteropServices.COMException.

                      Me.AxAgUiAxVOCntrl1.Application.ExecuteCommand("Bad command")
                  Catch ex As System.Runtime.InteropServices.COMException
                      MsgBox("The command failed: " & ex.ErrorCode & " [" & ex.Message & "]")
                  End Try


This example shows how to execute the InstallInfoCon report and access the return information.
[Visual Basic .NET] Copy Code
Private Sub Command1_Click()

    Dim stkx As AGI.STKX.AgSTKXApplication
    Dim oType As Type = Type.GetTypeFromProgID("STKX11.Application")
    stkx = Activator.CreateInstance(oType)

    Dim res As AGI.STKUtil.AgExecCmdResult

    res = stkx.ExecuteCommand("New / Scenario Scenario1")
    res = stkx.ExecuteCommand("New / Scenario/Scenario1/Facility Facility1")
    res = stkx.ExecuteCommand("GetReport */Facility/Facility1 ""Eclipse Times""")

    Dim l As String
    Dim msg As String
    For Each l In res
        msg = msg & l & vbCrLf

    res = Nothing
    stkx = Nothing

End Sub

See Also

© 2017 Analytical Graphics, Inc. All Rights Reserved.

STK Engine for UNIX 11.3.0