Part 13.3: Integrating STK with Excel

STK Pro, STK Premium (Air), STK Premium (Space), or STK Enterprise
You can obtain the necessary licenses for this tutorial by contacting AGI Support at support@agi.com or 1-800-924-7244.

Ensure you are working out of one module at a time. Some users have noted that Microsoft Excel will generate additional code modules if you relaunch the Excel workbook.

The results of the tutorial may vary depending on the user settings and data enabled (online operations, terrain server, dynamic Earth data, etc.). It is acceptable to have different results.

Capabilities covered

This lesson covers the following STK Capabilities:

  • STK Pro
  • STK Integration

Problem statement

Developers, engineers and operators need to quickly and easily automate repetitive tasks from outside of the STK application, integrate STK with other applications, such as Microsoft Excel, MATLAB, and Python, develop custom applications and leverage the AGI Object Model collection of COM libraries from other applications. You want to be able to create, drive and extract data from a simple STK scenario using Excel. You need to understand access to the following Application Programming Interfaces (API): the STK Object Model and Connect. Finally, you require a basic comprehension of STK Programming Help.

Solution

Use Excel to create a new instance of STK and expose the object root. Next, build a new scenario, populating it with a Satellite object and multiple Target objects. Create an access between the Satellite object and a selected Target object. Use the data providers, groups, and elements to retrieve access times from STK into Excel. Download, install and use the STK Excel Add-in plugin. Learn the power of STK Programming Help.

What you will learn

Upon completion of this tutorial, you will have a basic understand of the following:

  • STK Programming Help
  • STK Object Model
  • Connect
  • Data Providers
  • Sending and Receiving Data Between STK and Excel
  • STK Excel Add-in

STK and Excel should be shut down prior to starting this tutorial. This tutorial is not designed to teach you how to use Excel. It's an introduction to integrating Excel with STK and pulling data from STK into Excel. It's also an introduction to STK Programming Help and how important it is to be able to intelligently browse the help pages.

Video guidance

Watch the following video. Then follow the steps below, which incorporate the systems and missions you work on (sample inputs provided).

STK Programming Help

The STK Programming Help offers a wide variety of options to automate and customize STK and to integrate its technology into other applications. Only a small portion of the STK Programming Help is covered in this tutorial but it's a great starting point.

  1. Open your preferred Internet browser.
  2. Go to help.agi.com.
  3. Select STK Programming Help.

    STK Programming Help Link

If you do not have an internet connection, you can find the Programming Help by extending the Help menu inside STK and selecting Programming Interface Help.

Integrating STK with other applications

STK’s Integration capability enables you to automate repetitive tasks from outside the STK application, integrate STK with other applications — such as Excel and MATLAB — develop custom applications, and leverage the AGI Object Model collection of COM libraries from other applications.

  1. Choose Select the Right Technology in the contents list on the left side of STK Programming Help.
  2. Select Integrate Technologies.
  3. Select clickable decision tree on the Integrate With Other Applications page.
  4. Take a moment to view the page and click some of the icons.
  5. There are multiple clickable decision trees available in STK Programming Help. You can use the trees to quickly locate help pages that you need to be successful when using integration.

Automating repetitive tasks

To automate repetitive tasks in STK, you can use HTML, Connect, and STK Objects to build tools that are accessible from within STK.

  1. Return to STK Programming Help.
  2. Choose Select the Right Technology in the contents list.
  3. Select Automate Tasks.
  4. Select clickable decision tree on the Automate Repetitive Tasks page.
  5. Take a moment to view the page and click some of the icons.

Extending AGI products

AGI provides a variety of ways to extend our products. These extensibility mechanisms can be divided into two distinct areas: user interface extensibility and engine extensibility.

  1. Return to STK Programming Help.
  2. Choose Select the Right Technology in the contents list.
  3. Select Extend AGI Products.
  4. Click clickable decision tree on the Extend AGI Products Using Plugins and Custom User Interfaces page.
  5. Take a moment to view the page and click some of the icons.
  6. There are other links throughout that aren't covered here. Take some time later on to become familiar with them.

Visualize

STK X allows developers to add advanced STK 2D, 3D visualization and analytical capabilities to applications with little effort.

  1. Return to STK Programming Help.
  2. Choose Library Reference in the contents list.
  3. Select Controls.
  4. Select STK X.
  5. Take some time to familiarize yourself with the contents of this page.

Using Core Libraries

The STK API consists of two major sub-systems: Connect and the STK Object Model.

  • Connect is a library of string commands for STK, originally designed to operate over a TCP/IP socket.
  • The STK Object Model is an object-oriented interface to STK, built on Microsoft COM technology.
  1. Return to STK Programming Help.
  2. Choose Using Core Libraries in the contents list.
  3. Note the advantages and disadvantages of using each library.
  4. The choice of Connect or Object Model should be driven by the requirements of the application and the needs of the developer. It is important to note, however, that this need not be an exclusive choice. Connect commands can be used in a COM application side-by-side with Object Model Code.

Naming conventions

The STK Object Model contains naming conventions for classes, interfaces and enumerations.

Naming Conventions

  1. Return to STK Programming Help.
  2. Choose Library Reference in the contents list.
  3. Select STK Object Model.
  4. Select Naming Conventions.
  5. Note the various naming conventions described on the Naming Conventions Used In the Various Core Libraries page.
  6. Select Abbreviations in the contents list.
  7. Note the abbreviations most commonly used in the names of classes, interfaces and other types in the STK Object Model.

Model diagrams

For the serious programmer, you can use diagrams to see how the STK traffic flow is connected. That way, you know what's to the right, left, above and below, all while deep-linking to the individual IAg interface pages.

  1. Return to STK Programming Help.
  2. Choose Using Core Libraries in the contents list.
  3. Select STK Object Model.
  4. Select STK Objects.
  5. Select Diagrams.
  6. Select STK Object Model Diagram (PDF) on the STK Objects Object Model Diagrams page.
  7. Zoom into the page for clarification if desired.
  8. Take some time to look at the STK 10.0 Object Model Diagrams PDF.
  9. Diagrams exist for the following:

  10. Close the STK Object Model Diagram (PDF) when finished.
  11. Keep STK Programming Help open.

STK Excel Add-in

The STK Excel Add-in is a set of VBA libraries, macros, forms and toolbars that let Excel users interact with STK and STK scenarios directly from Excel. You can pull data from STK into Excel or pass certain data types from Excel into STK. The STK Excel add-in may already do what you require. At the end of this tutorial, the STK Excel Add-in tool will be used, so now is a good time to install it on your computer.

  1. Go to https://www.agi.com/ in your preferred browser.
  2. Click SIGN IN at the top of the page.
  3. Select Sign In in the shortcut menu.
  4. Enter your credentials in the Sign In page.
  5. Click SIGN IN.

Downloads

  1. After signing in, at the top of the page, select Support.
  2. Select Downloads once the menu opens.
  3. If presented, read the Software License Agreement. Otherwise, go to step 5.
  4. Click ACCEPT.
  5. On the Software Downloads page, locate Data and Auxiliary Extensions.
  6. Select STK Excel Add-in (v12.0.0).
  7. This will download the install file as a zipped folder to your designated download location.

Installing the STK Excel Add-in

  1. Go to your download location.
  2. Unzip (Extract All) the STKExcelAdd-in_v12.0.0.zip folder to your preferred location.
  3. Open the extracted (unzipped) STKExcelAdd-in_v12.0.0 folder.
  4. Double-click STKExcelAdd-in_v12.0.0.
  5. If you receive a security warning, click Run.
  6. Run the installer.
  7. Keep STK Programming Help open.
  8. Close any open folders and web pages that your desire.

Configuring Excel

Enable the Developer tab and the STK Excel Add-in.

  1. Launch Excel.
  2. Click Blank workbook once Excel launches.

Blank Workbook

Excel Developer Tab

Turn on the Developer tab in Excel if you want to create a macro, export and import XML files or insert controls. If it's not already turned on, complete the following steps.

  1. Right-click anywhere on the ribbon.
  2. Select Customize the Ribbon...
  3. Excel Ribbon

  4. Select Main tabs (if necessary) under Customize the Ribbon shortcut menu in the Excel Options dialog box.
  5. Select the Developer check box.
  6. Main Tabs

  7. Click OK.

Turning on the STK Excel Add-in

  1. Select the Developer tab.
  2. Developer Tab

  3. Click Excel Add-ins.
  4. Select the Stk Add-in 12 X64 check box in the Add-ins dialog box.
  5. Click OK.
  6. Close Excel. This is required.

Creating an Excel Workbook

Create a workbook and save the file to a custom folder.

  1. Launch Excel.
  2. Click Blank Workbook.
  3. Select the File menu when the workbook opens.
  4. Click Save As in the contents list on the left.
  5. Select Browse.
  6. Select Desktop in the Save As dialog box.
  7. Select New folder in the menu bar.
  8. Rename New folder to STK_Excel.
  9. Click Open.
  10. Type STK_Excel_Workbook in the File name: field.
  11. Open the Save as type: shortcut menu.
  12. Select Excel Macro-Enabled Workbook.
  13. Click Save.

Form Control Button

Turn on the Excel Form Control button.

  1. Select the Developer tab.
  2. Click Insert.
  3. Click Button (Form Control) in the shortcut menu.
  4. Form Controls

  5. Hold down your left mouse button and draw out a small box (2 cells by 2 cells) in the Excel workbook.
  6. Small Button Box

  7. Type Launch_STK in the Macro name: field when the Assign Macro tool dialog box opens.
  8. Macro Name

  9. Click New.

Change the Button's Name

Give the button a unique name.

  1. Bring the Excel workbook to the front.
  2. Highlight the button name (e.g. Button 1) in the button.
  3. Type Launch STK.

Creating an STK Instance from Excel

You will use the Excel script file to build a simple STK scenario from which you will extract data into Excel. You can use VB script or the STK object model and for automation you can use your preferred method. STK Connect will be demonstrated in this tutorial. All the components of Integration are fully documented, and AGI maintains a GitHub repository of Code samples to help you get started with the STK Object Model . There is a learning curve, so start with STK Programming Help.

Ensure you are working out of one module at a time. Some users have noted that Microsoft Excel will generate additional code modules if you relaunch the Excel workbook.

  1. Bring the Microsoft Visual Basic for Applications - [Module 1 (Code)] window to the front.
  2. Create global variables by Typing or copying and pasting the following code inside the Visual Basic editor above Sub Launch_STK (). This will create global variables.
  3. Dim app
    Dim root
    Dim scenario

  4. Create a new instance of STK. Type or copy and paste the following Code within Sub Launch_STK().
  5. ' TASK 1
    ' Create new instance of STK using the CreateObject Method
    Set app = CreateObject("STK.Application")
    app.Visible = True
    ' Expose the STK application root using the Personality2 Property
    Set root = app.Personality2

    Launch STK Button and Task 1 Code

  6. Click Save STK_Excel_Workbook.xlsm (Ctrl+ S) ().

Understanding Task 1

Set app = CreateObject("STK.Application")

The CreateObject Method expects a string, in this case STK.Application.

CreateObject Method

  1. Bring STK Programming Help to the front.
  2. Choose Library Reference in the Contents list.
  3. Select Application Object Model.
  4. Select STK UI Application.
  5. In Classes, Select AgUiApplication on the Project Overview page.
  6. In Interfaces, select IAgUiApplication on the AgUiApplication Object page.
  7. In Public Methods, select CreateObject on the IAgUiApplication Interface page.
  8. In Syntax, look at the [Visual Basic .NET] Syntax on the CreateObject Method (IAgUiApplication) page.

Making STK Visible

app.Visible = True

Visible Property (IAgUiApplication) makes the main window visible.

Visible Property

  1. Select Library Reference in the contents list.
  2. Select Application Object Model.
  3. Select STK UI Application.
  4. Select Properties.
  5. Select Visible Property (IAgUiApplication).

Exposing the STK Application Root

Set root = app.Personality2

Personality2 Property (IAgUiApplication) returns a new instance of the root object of the STK Object Model.

Personality2 Property

  1. Select Library Reference in the contents list.
  2. Select Application Object Model.
  3. Select STK UI Application.
  4. Select Properties.
  5. Select Personality2 Property (IAgUiApplication).

Running the Sub Routine

You can run the sub routine by clicking the Launch STK button or by selecting the sub routine and clicking the green Run button.

  1. Bring the Microsoft Visual Basic for Applications - [Module 1 (Code)] window to the front.
  2. Click Save STK_Excel_Workbook.xlsm (Ctrl+ S) ().
  3. Save Button

  4. Click inside the Sub Launch_STK () code.
  5. Click Run Sub/UserForm (F5) ().
  6. Sub/UserForm (F5) Button

    The STK application window appears.

    After testing a sub routine, when you return to the workbook and create a new button, STK will close.

Creating a New STK Scenario

After launching STK, create a new scenario and set the time period.

  1. Return to the Excel workbook.
  2. Click Insert in the Developer tab.
  3. Click Button (Form Control) in the Form Controls window.
  4. While in the Excel workbook, hold down your left mouse button and draw out a new button below the Launch STK button.
  5. Type Create_Scenario in the Macro name: field when the Assign Macro dialog box opens.
  6. Click New.
  7. Return to the Excel workbook.
  8. Change the name of Button 2 to Create Scenario.
  9. Bring the Microsoft Visual Basic for Applications - [Module 1 (Code)] window to the front.
  10. Type or copy and paste the following Code within Sub Create_Scenario ().
  11. ' TASK 2
    ' Create a new scenario.
    root.NewScenario("New_Scenario")
    Set scenario = root.CurrentScenario
    ' Set the analytical time period.
    notUsed = scenario.SetTimePeriod("Today", "+24hr")
    ' Reset the animation time.
    notUsed = root.Rewind()

    You will create a new scenario called New_Scenario.

    Task 2 Code

  12. Click Save STK_Excel_Workbook.xlsm (Ctrl+ S) ().

Understanding Task 2

This section will show you another way to use STK Programming Help.

Understanding NewScenario Method

NewScenario Method (IAgStkObjectRoot) creates a new scenario and expects a scenario name as a string.

Throughout this tutorial, code from the Tasks will be in BOLD text. You will also find resources to understand the code's function.

You use this method in line 3 of Task 2: root.NewScenario ("New_Scenario")

NewScenario Method

  1. Return to STK Programming Help.
  2. Type NewScenario in the search field.
  3. Click Enter.
  4. Select STKObjects~IAgStkObjectRoot~NewScenario.

Understanding CurrentScenario Property

CurrentScenario Property (IAgStkObjectRoot) returns a Scenario object or null if no scenario has been loaded yet.

You use this method in line 4 of Task 2: Set scenario = root.CurrentScenario

CurrentScenario Property

  1. Return to STK Programming Help.
  2. Type CurrentScenario in the search field.
  3. Click Enter.
  4. Select STKObjects~IAgStkObjectRoot~CurrentScenario.

Understanding SetTimePeriod()

SetTimePeriod Method (IAgScenario) sets the Scenario time period. startTime/stopTime use DateFormat Dimension.

You use this method in line 6 of Task 2: notUsed = scenario.SetTimePeriod("Today", "+24hr")

SetTimePeriod Method

  1. Return to STK Programming Help.
  2. Enter SetTimePeriod in the search field.
  3. Click Enter.
  4. Select STKObjects~IAgScenario~SetTimePeriod.

You will see throughout the code the variable notUsed. VBA expects something back even if STK doesn't return anything. Therefore, whenever you change properties of an object such as time or coordinates, you will use the variable notUsed.

Understanding Rewind()

Rewind Method (IAgAnimation) is used to stop and reset the animation.

You use this method in line 8 in Task 2: notUsed = root.Rewind()

Rewind Method

  1. Return to STK Programming Help.
  2. Type Rewind in the search field.
  3. Click Enter.
  4. Select STKObjects~IAgAnimation~Rewind.C

Summary of Task 2

In Task 2, you are creating a Scenario object named New_Scenario and setting its analysis time from midnight local time based on your time zone (Today) and running the scenario for 24 hours. Then you are essentially clicking the red Reset button in the Animation Toolbar of STK to reset your scenario time.

STK Programming Help Search Examples

These were two examples of using STK Programming Help. When you are looking at Code snippets and such, in the search window, you can type something from the Code such as Personality2 and it will provide choices to select from. It would take a long time to browse the STK Programming Help throughout this tutorial, so hyperlinks are used to simplify and speed things up. However, practice makes perfect, so feel free to search on your own.

Running Both Sub Routines

  1. Bring the Microsoft Visual Basic for Applications - [Module 1 (Code)] window to the front.
  2. Click Save (Ctrl+ S) () in STK_Excel_Workbook.xlsm.
  3. Bring the Excel workbook to the front.
  4. Click Launch STK.
  5. Click Create Scenario once STK opens.
  6. Bring STK to the front.

Viewing the Scenario object properties

  1. Right-click on New_Scenario () in the Object Browser.
  2. Select Properties ().
  3. Note the Analysis Period Start: and Stop: times when the Properties Browser opens.
  4. Click Cancel to close the New_Scenario's () properties ().
  5. Look at Current Scenario Time in the Animation Toolbar. You set it for midnight local time (Today). You will see that the code reset it to the equivalent UTCG date and time.
  6. Return to the Excel workbook.

Configuring Target1 Objects

Populate the scenario by inserting 25 Target () objects.

  1. Type the following column headers into Excel:
  2. Cell Value
    F1 Target Name
    G1 Latitude
    H1 Longitude
  3. Select cell F2.
  4. Enter Target.
  5. Select cell G2.
  6. Copy and paste the following Excel RAND function into the Formula Bar:
  7. =(RAND()-0.5)*180

  8. Click Enter. The Excel RAND function returns a random number between 0 and 1. This Code will return a random number between -90 and 90.
  9. Select cell H2.
  10. Copy and paste the following Excel RAND function into the Formula Bar:
  11. =(RAND()-0.5)*360

  12. Click Enter. This Code will return a random number between -180 and 180. Your values will be different from the image.
  13. Target Name, Latitude and Longitude

Creating Multiple Targets and Random Latitudes and Longitudes

  1. Select cell F2.
  2. Hold the Shift key and select cell H2.
  3. Place your cursor on the small black box located at the lower right corner of cell H2.
  4. Small Black Box

  5. Hold down your left mouse button and drag the black box to cell H26 and release your mouse button. This will create 25 targets and 25 random latitudes and longitudes (your values will be different than the example).
  6. Twenty Five Targets and Random Locations

  7. Click Save (Ctrl+ S) () while in the Excel workbook.

Inserting the Targets into STK

Insert the targets into STK using Target () objects.

  1. Click Insert in the Developer tab.
  2. Click Button (Form Control) in the Form Controls window.
  3. While in the Excel workbook, hold down your left mouse button and draw out a new button below the Create Scenario button.
  4. Type Insert_Targets in the Macro name: field of the Assign Macro dialog box.
  5. Click New.
  6. Return to the Excel workbook.
  7. Change the name of Button 3 to Insert Targets.
  8. Bring the Microsoft Visual Basic for Applications - [Module 1 (Code)] window to the front.
  9. Type or copy and paste the following Code within Sub Insert_Targets().
  10. ' TASK 3
    ' Add a target object to the scenario.
    For i = 2 to 26
    Dim target
    Set target = root.CurrentScenario.Children.New(23, Range("F" & i).Value)
    ' Move the Target object to a desired location.
    notUsed = target.Position.AssignGeodetic(Range("G" & i).Value, Range("H" & i).Value, 0.0)
    Next

    Task 3 Code

  11. Click Save (Ctrl+ S) () in STK_Excel_Workbook.xlsm.

Understanding Task 3

Review the following sections to learn more about each line of Task 3 and discover resources in the STK Programming Help.

Understanding how to loop through rows in the code

You are looping through rows 2 to 26 of your Excel workbook. You create a new Target object on each line for 25 targets total.

You use a loop in line 3 of Task 3: For i = 2 to 26

Understanding the CurrentScenario Method

You use the CurrentScenario Method in line 5 of Task 3: Set target = root.CurrentScenario.Children.New(23, Range("F" & i).Value)

You will navigate to the CurrentScenario Method in the STK Programming Help for more information.

  1. Return to STK Programming Help.
  2. Type currentscenario in the search field.
  3. Click Enter.
  4. Select STKObjects~IAgStkObjectRoot~CurrentScenario from the search results.
  5. Select IAgStkObject

  6. Select IAgStkObject in the Visual Basic .NET Syntax list.
  7. Select Children in Public Properties.

Children Property

Children Property (IAgStkObject) returns a collection of direct descendants of the current object.

  1. Select IAgStkObjectCollection from the Visual Basic .NET Syntax list.
  2. Select New In Public Methods.

Select IAgStkObjectCollection

New Method

New Method (IAgStkObjectCollection) creates an STK object using specified class and instance name.

  1. Select AgESTKObjectType from the Visual Basic .NET Syntax list.
  2. AgESTKObjectType Enumeration shows the object type enumerations, associated value and the STK objects.

  3. Scroll down the Member list until you locate eTarget. To insert a new Target () object, you can use eTarget or the value 23. Your code uses the value 23.
  4. Next, STK wants a string for the name. You want the name in cell F2. To use all the target names, in VBA, you use Range. You want cell F and the ampersand (&) allows you to concatenate strings. It will start in F2 and finish in F26.

Select AgESTKObjectType

Assigning Locations of objects

In short, the Position Property gets the position of the target. The AssignGeodetic Method is a helper method to assign the position using the Geodetic representation. Learn more about the Position Property (IAgTarget) and the AssignGeodetic Method (IAgPosition) in the STK Programming Help.

You use both of these method in line 7 of Task 3: notUsed = target.Position.AssignGeodetic(Range("G" & i).Value, Range("H" & i).Value, 0.0)

Within the AssignGeodetic method:

  • Range("G" & i).Value will read cells G2 though G26 for the latitudes.
  • Range("H" & i).Value, 0.0) will read cells H2 though H26 for the longitudes. The altitude is 0.0 for all the targets which will place them on top of the WGS84 ellipsoid if you don't have terrain or on top of the terrain if you're using terrain such as Terrain Server. In the Code, Excel converts the value 0.0 is converted to 0#. (Don't worry about it.)

Running all three sub routines

  1. Bring the Excel workbook to the front.
  2. Click Launch STK in the Excel workbook.
  3. Click Create Scenario once STK opens.
  4. After the scenario is created, click Insert Targets.
  5. Bring STK to the front.
  6. You created an instance of STK, created a scenario with a 24 hour analysis period and inserted 25 random Target objects around the Earth.

    2D Graphics View of Random Targets Around the Earth

Inserting a Satellite Object into STK

You have launched STK, created a new scenario, set the time period and inserted 25 randomly placed Target () objects. Now you will insert and propagate a Satellite () object.

  1. Return to the Excel workbook.
  2. Click Insert in the Developer tab.
  3. Click Button (Form Control) in the Form Controls window.
  4. While in the Excel workbook, hold down your left mouse button and draw out a new button below the Insert Targets button.
  5. Type Insert_Satellite in the Macro name: field of the Assign Macro dialog box.
  6. Click New.
  7. Bring the Excel workbook to the front.
  8. Change the name of Button 4 to Insert Satellite.
  9. Bring the Microsoft Visual Basic for Applications - [Module 1 (Code)] window to the front.
  10. Type or copy and paste the following Code within Sub Insert_Satellite ().
  11. ' TASK 4
    ' Add a Satellite object to the scenario.
    Dim satellite
    Set satellite = root.CurrentScenario.Children.New(18, "LeoSat")
    ' Propagate the Satellite object's orbit.
    root.ExecuteCommand ("SetState */Satellite/LeoSat Classical TwoBody UseScenarioInterval 60 ICRF ""UseAnalysisStartTime"" 7200000.0 0.0 90 0.0 0.0 0.0")

    Task 4 Code

  12. Click Save (Ctrl+ S) () in STK_Excel_Workbook.xlsm.

Understanding Task 4

Review the following sections to learn how each line of Task 4 works.

Understanding the Children Property in Task 4

You use the Children property to insert a Satellite () object in this case. This code uses the value 18 which loads a Satellite () object into your scenario called LeoSat. Previously, you used similar code to insert a Target () object into the scenario.

You used this property in line 4 of Task 4: Set satellite = root.CurrentScenario.Children.New(18, "LeoSat")

Understanding the ExecuteCommand() Method

You use the ExecuteCommand Method to propagate the Satellite () object. In general, the method executes a custom CONNECT action. Learn more about the connect command ExecuteCommand Method (IAgStkObjectRoot) in the STK Programming Help.

You used this method in line 6 of Task 4: root.ExecuteCommand ("SetState */Satellite/LeoSat Classical TwoBody UseScenarioInterval 60 ICRF ""UseAnalysisStartTime"" 7200000.0 0.0 90 0.0 0.0 0.0")

SetState Connect Command

Look at the Alphabetical Listing of Connect Commands to understand the SetState connect command.

  1. Return to STK Programming Help.
  2. Choose Library Reference in the Contents list.
  3. Select Connect Command Library.
  4. Click Alphabetical Listing of Connect Commands from the Connect Command Listings page.
  5. Click S at the top of the Alphabetical Listing page.
  6. Select the SetState Classical command.
  7. Scroll through the SetState Classical page and note the following:
    • Syntax will help you understand the input values of your SetState command.
    • The description chart explains each input and its associated unit.
    • In the Examples section, there are multiple examples that can be copied and edited for your particular scenario.

Running all four sub routines

  1. Return to the Excel workbook.
  2. Click Launch STK.
  3. Click Create Scenario once STK opens.
  4. After the scenario is created, click Insert Targets.
  5. After the targets are inserted, click Insert Satellite.
  6. Bring STK to the front.

You created an instance of STK, a scenario with a 24 hour analysis period, inserted 25 random Target () objects around the Earth and inserted and propagated a Satellite () object.

3D View of Random Target Objects and Satellite Object

Creating an Access

Determine when the LeoSat () can access Target1 ().

  1. Return to the Excel workbook.
  2. Click Insert in the Developer tab.
  3. Click Button (Form Control) in the Form Controls window.
  4. While in the Excel workbook, hold down your left mouse button and draw out a new button below the Insert Satellite button.
  5. Type Compute_Access in the Macro name: field of the Assign Macro dialog box.
  6. Click New.
  7. Bring the Excel workbook to the front.
  8. Rename Button 5 to Compute Access.
  9. Bring the Microsoft Visual Basic for Applications - [Module 1 (Code)] window to the front.
  10. Type or copy and paste the following Code within Sub Compute_Access ().

' TASK 5
' Compute Access between the satellite and the target
Dim sat
Set sat = root.GetObjectFromPath("Satellite/LeoSat")
Dim tar1
Set tar1 = root.GetObjectFromPath("Target/Target1")
Dim access
Set access = sat.GetAccessToObject(tar1)
'Compute access
access2 = access.ComputeAccess()

Understanding Task 5

Review these sections to understand more about Task 5.

Understanding GetObjectFromPath()

In short, the method gets the object instance that matches the path provided. Learn more about the GetObjectFromPath Method (IAgStkObjectRoot) in the STK Programming Help.

You use this method in lines 4 and 6 from Task 5:

Set sat = root.GetObjectFromPath("Satellite/LeoSat")

Set tar1 = root.GetObjectFromPath("Target/Target1")

Understanding the GetAccessToObject()

In short, the method returns an IAgStkAccess object to compute access to. Learn more about the GetAccessToObject Method (IAgStkObject) in the STK Programming Help.

You use this method in line 8 from Task 5: Set access = sat.GetAccessToObject(tar1)

Understanding the ComputeAccess() Method

In short, the ComputeAccess() recomputes the access between two objects. Learn more about the ComputeAccess Method (IAgStkAccess) in the STK Programming Help.

You use this method in line 10 in Task 5: access2 = access.ComputeAccess()

Data Providers

The content of a report or graph is generated from the selected data providers for the report or graph style. You can view data providers, groups and elements when using the Report & Graph Manager inside of STK. Data providers are also broken out in detail in STK Programming Help.

  1. Return to STK Programming Help.
  2. Select Library Reference in the Contents list.
  3. Select Data Providers Reference.
  4. On the Data Providers by Object page, you can spend a lot of time looking at an object's data providers, groups and elements.
  5. Keep this page open.

Retrieve and View the Access Data in Excel

You created an access from LeoSat () to Target1 (). Retrieve and view the access data in Excel.

  1. Bring the Microsoft Visual Basic for Applications - [Module 1 (Code)] window to the front.
  2. Type or copy and paste the following Code at the bottom of the Sub Compute_Access().
  3. ' TASK 6
    ' Pull the data of interest out of the access object
    Dim dp
    Set dp = access.DataProviders("Access Data")
    Dim results
    Set results = dp.Exec(scenario.StartTime, scenario.StopTime)
    accessNumber = results.DataSets(0).GetValues()
    accessStart = results.DataSets(1).GetValues()
    accessStop = results.DataSets(2).GetValues()
    accessDuration = results.DataSets(3).GetValues()
    ' Create columns
    Range("J1") = results.DataSets(0).ElementName
    Range("K1") = results.DataSets(1).ElementName
    Range("L1") = results.DataSets(2).ElementName
    Range("M1") = results.DataSets(3).ElementName
    ' Write the data into Excel.
    For i = 0 To UBound(accessNumber)
    Range("J" & i + 2) = accessNumber(i)
    Range("K" & i + 2) = accessStart(i)
    Range("L" & i + 2) = accessStop(i)
    Range("M" & i + 2) = accessDuration(i)
    Next

  4. Click Save STK_Excel_Workbook.xlsm ().

Tasks 5 and 6

Understanding Task 6

Review the sections to learn about the different methods and properties in Task 6. Also, you will discover resources in the STK Programming Help to understand these methods and properties further.

Understing the DataProviders Property

The DataProviders Property returns the object representing a list of available data providers for the object. Learn more about the DataProviders Property (IAgStkAccess) in the STK Programming Help.

You use this property in line 4 of Task 6: Set dp = access.DataProviders("Access Data")

  1. Return to STK Programming Help.
  2. Select Access on the Data Providers by Object page. This page provides data providers available for the Access object.
  3. Select Access Data in the Available Data Providers list. Access Data is the specified data provider.
  4. Select Access in the Data Provider Variants list.
  5. Look at the Data Provider Elements list to understand the following code.

Understanding the Exec() Method

The Exec Method computes the data within a specified Start and Stop time. Learn more about the Exec Method (IAgDataPrvTimeVar) in the STK Programming Help.

You use this method in line 6 of Task 6: Set results = dp.Exec(scenario.StartTime, scenario.StopTime)

Understanding the DataSets() Property and the GetValues Method

The DataSets() Property returns a collection of data sets within a specified interval. The GetValues retrieves an array of values of the elements in the dataset. In this instance, you're creating an access from the satellite to the target based on the scenario start and stop times.

When pulling data from the data provider elements list, it follows the sequence as seen in the list. For example, the first element, Access Number, is 0 (zero). Start Time is 1 (one), Stop Time is 2 (two) and Duration is 3 (three). In the code, accessNumber = results.DataSets(0).GetValues() simply means that you are you are pulling the results from the data provider (Access Data) and then the data provider element Access Number.

You can learn more about the DataSets Property (IAgDrInterval) and the GetValues Method (IAgDrDataSet) in the STK Programming Help.

You use this property and method in lines 7 to 10 of Task 6:

accessNumber = results.DataSets(0).GetValues()

accessStart = results.DataSets(1).GetValues()

accessStop = results.DataSets(2).GetValues()

accessDuration = results.DataSets(3).GetValues()

Understanding the ElementName Property

You use the DataSets() Property again, but you pair that property with a new one. The ElementName Property returns the name of the dataset. In Task 6, you are writing the element names as headers for columns J1 through M1. Learn more about the ElementName Property (IAgDrDataSet) in the STK Programming Help.

You use this property in lines 12 to 15 of Task 6:

Range("J1") = results.DataSets(0).ElementName

Range("K1") = results.DataSets(1).ElementName

Range("L1") = results.DataSets(2).ElementName

Range("M1") = results.DataSets(3).ElementName

Understanding filling the data in your table

You use a loop to add data to your table in line 17 to 21 in Task 6:

For i = 0 To UBound(accessNumber)

Range("J" & i + 2) = accessNumber(i)

Range("K" & i + 2) = accessStart(i)

Range("L" & i + 2) = accessStop(i)

Range("M" & i + 2) = accessDuration(i)

You will loop through all the data that it returns and write it to the appropriate cell.

Run all five sub routines

  1. Bring the Excel workbook to the front.
  2. Click Launch STK.
  3. Click Create Scenario once STK opens.
  4. After the scenario is created, click Insert Targets.
  5. After the targets are inserted, click Insert Satellite.
  6. After the satellite is inserted, click Compute Access. Your data will look similar to but different than the following example.

Buttons, Targets, and Access Data

Format cells

Excel formats the start and stop times differently than SKT (e.g. day, month, year, time). You can select the cells containing the start and stop times, right-click on the selection, open the Format Cells option and set the format to dd mmm yyyy hh:mm:ss.000. Or you can use the following Code.

  1. Bring the Microsoft Visual Basic for Applications - [Module 1 (Code)] window to the front.
  2. Type or copy and paste the following Code at the bottom of the Sub Compute_Access().
  3. ActiveSheet.Columns("K").Select
    Selection.NumberFormat = "dd mmm yyyy hh:mm:ss.000"
    ActiveSheet.Columns("L").Select
    Selection.NumberFormat = "dd mmm yyyy hh:mm:ss.000"

  4. Click Save STK_Excel_Workbook.xlsm (Ctrl+ S) ().
  5. Bring the Excel workbook to the front.
  6. Click Compute Access. Your data will look similar to but different than the following example.
  7. Click Save ().

Reformatted Cells

STK Excel Add-in

At the beginning of the tutorial, you downloaded and installed the STK Excel Add-in. Use that now.

  1. Select the Add-ins tab.

Custom Toolbars

If you're using the STK Excel Add-in, in the Excel ribbon, you should see the Custom Toolbars.

ButtonFunction
Create or Attach to STK 12
Open or Close a scenario 12
Extract Data From an STK 12 Data Provider
Insert Data Into STK 12
Undo the last Get Data operation
About this Add-in

Attaching the Excel Workbook to STK

Since you already have a running instance of STK, you can attach Excel to your scenario.

  1. Select cell P in the Excel workbook. You want an empty cell plus three empty cells to the right. You will be choosing four elements.
  2. Click Create or Attach to STK 12 () from the Custom Toolbars.
  3. Select Attach to an existing STK 12 application instance.
  4. Click OK to close the information window.
  5. Click Extract Data From an STK 12 Data Provider () to open the Generate Data Provider Report tool.

Generate Data Provider Report Tool

Selecting your data providers

  1. Select Satellite/LeoSat from the object list.
  2. Expand () LLA State (Data Provider) in the Data Providers: list.
  3. Expand () Fixed (Data Provider Group).
  4. Select the following data provider elements.
    • Time
    • Lat
    • Lon
    • Alt
  5. Use the default Start Time and Stop Time values.
  6. Change Step (sec): to 3600. This will make the data easier to read.
  7. Click Generate.
  8. Close the Generate Data Provider Report tool.
  9. You can expand columns P/Q/R/S in the Excel workbook if desired to see all of the data.
  10. You can see the Time, Latitude, Longitude, and Altitude of the satellite in one hour increments over the 24 hour analysis period.

    Data Provider Report

Summary

You began by viewing a small portion of the STK Programming Help pages. Then you performed the following:

  • Downloaded and installed the STK Excel Add-in.
  • Opened Excel and enabled the Developer tab and turned on the STK Excel Add-in.
  • After closing and then opening Excel, you created an Excel Macro-Enabled Workbook (*.xlsm).
  • Created the first button and code which launched an instance of STK.
  • Created the second button and code to create a new Scenario object with a run time of 24 hours and reset the scenario to the new analysis time period.
  • In the Excel workbook, you created three columns: Target Name, Latitude and Longitude. In the Latitude column, you set a random number formula that entered values between -90 and 90. In the Longitude column, you set a random number formula that entered values between -180 and 180. You created 25 random targets.
  • Created the third button and code which loaded 25 random Target objects into the scenario.
  • Created a fourth button and code which propagated a LEO Satellite in the scenario.
  • Created a fifth button and code that computed access between the Satellite object and a Target object and imported the access times into Excel.
  • Changed the fifth button code to format the access times to match the format in STK.
  • Used the STK Excel Add-in to import selected LLA Data Provider Elements concerning the Satellite object into Excel.

Close Excel

  1. Return to Excel.
  2. Press Ctrl+S on your keyboard to save your workbook.
  3. Close Excel. This will also close STK.

On Your Own

Throughout the tutorial, hyperlinks were provided that pointed to in depth information concerning the STK Object Model and Connect. Now's a good time to go back through this tutorial and view that information. Obviously, there is a lot to learn. However, this tutorial should have provided some familiarization on how to use STK Programming Help. Explore!

You can try multiple tutorials to become more familiar with the STK Object Model and Connect: Tutorials, Code Samples, Code Snippets, and Online Resources.