Controlling Aircraft in STK Engine at Runtime with Python

stk-aircraft-control-manya-technologies

When working with STK Engine you often need more than just creating aircraft and running a predefined simulation — you may want interactive runtime control. For example, nudging an aircraft left, right, up, or down during animation.

In this post, we’ll walk through a minimal example using Python + Tkinter that does exactly that:

  • Create one or more aircraft in STK.
  • Start/stop/reset animation.
  • Move a selected aircraft left, right, up, or down at runtime.

We’ll keep things simple and strip away extras like 2D/3D view switching or aircraft detail panels.


1. Starting STK Engine

The first step is to launch STK Engine and open a fresh scenario:

from agi.stk12.stkengine import *
from datetime import datetime

stk = STKEngine.StartApplication(noGraphics=False)
root = stk.NewObjectRoot()

# Close existing scenario and create a new one
try:
    root.CurrentScenario.Close()
except:
    pass

scenario_name = "Minimal_AC_" + datetime.now().strftime("%Y%m%d_%H%M%S")
root.NewScenario(scenario_name)

This ensures you always start with a clean workspace.


2. Creating an Aircraft

Aircraft in STK are defined by waypoints. In our minimal version we give each aircraft just two waypoints and propagate the route:

def create_aircraft(name, lat1, lon1, alt1, lat2, lon2, alt2):
    ac = root.CurrentScenario.Children.New(1, name)   # 1 = Aircraft
    ac.SetRouteType(9)  # ePropagatorGreatArc
    route = ac.Route

    wp1 = route.Waypoints.Add()
    wp1.Latitude, wp1.Longitude, wp1.Altitude = lat1, lon1, alt1

    wp2 = route.Waypoints.Add()
    wp2.Latitude, wp2.Longitude, wp2.Altitude = lat2, lon2, alt2

    route.Propagate()
    return ac

That’s all it takes — STK now has a flyable aircraft object.


3. Animation Control

STK’s animation clock is controlled with simple commands:

root.ExecuteCommand('Animate * Start')   # start
root.ExecuteCommand('Animate * Pause')   # pause
root.ExecuteCommand('Animate * Reset')   # reset

We’ll hook these into buttons in a minimal Tkinter GUI.


4. Moving an Aircraft

Instead of recreating aircraft, we can update its waypoint and re-propagate the route. For example, to move left/right (longitude) or up/down (altitude):

def move_aircraft(name, dlon=0, dalt=0):
    ac = root.CurrentScenario.Children.Item(name)
    wp = ac.Route.Waypoints.Item(1)  # edit first waypoint
    wp.Longitude += dlon
    wp.Altitude  += dalt
    ac.Route.Propagate()

Using this, you can bind simple controls:

  • Left ⟶ move_aircraft(name, -0.5, 0)
  • Right ⟶ move_aircraft(name, +0.5, 0)
  • Up ⟶ move_aircraft(name, 0, +1.0)
  • Down ⟶ move_aircraft(name, 0, -1.0)

Where longitude is in degrees and altitude in kilometers.


5. Minimal Tkinter UI

Finally, we add a tiny Tkinter interface:

from tkinter import Tk, Button

window = Tk()
window.title("STK Aircraft Control")

Button(window, text="Start", command=lambda: root.ExecuteCommand('Animate * Start')).pack()
Button(window, text="Pause", command=lambda: root.ExecuteCommand('Animate * Pause')).pack()
Button(window, text="Reset", command=lambda: root.ExecuteCommand('Animate * Reset')).pack()

Button(window, text="← Left", command=lambda: move_aircraft("AC_1", -0.5, 0)).pack()
Button(window, text="→ Right", command=lambda: move_aircraft("AC_1", +0.5, 0)).pack()
Button(window, text="⬆ Up", command=lambda: move_aircraft("AC_1", 0, +1)).pack()
Button(window, text="⬇ Down", command=lambda: move_aircraft("AC_1", 0, -1)).pack()

window.mainloop()

That’s it — one window with start/pause/reset buttons and arrow controls for the aircraft.


6. Putting It All Together

When you run the script:

  1. A new scenario is created in STK.
  2. An aircraft is added with two waypoints.
  3. Animation begins.
  4. You can click the buttons to steer the aircraft left, right, up, or down in real time.

Final Thoughts

This minimal setup demonstrates how to control aircraft interactively with STK Engine. From here, you could:

  • Bind the same functions to keyboard arrow keys.
  • Add multiple aircraft and a dropdown selector.
  • Replace longitude/altitude nudging with heading/velocity adjustments for more realistic turns.

By starting small and keeping only the essentials, you get a clean foundation for building more advanced flight control tools in STK.

If you’re looking to build advanced aerospace and defense simulations using STK, STK Engine, or DME components, our team at Manya Technologies can help. We specialize in developing custom mission planning tools, real-time visualization systems, and interactive 2D/3D simulators tailored to your requirements. With expertise in STK integration, GUI development, and data-driven simulation, we deliver robust and scalable solutions for training, analysis, and operational needs. Reach out to us to discuss how we can support your next simulation project.

If you’re interested in a full-fledged GIS solution, check out our flagship product PrithviGIS – a powerful QGIS-based platform for real-time geospatial visualization.

Check out our Live Aircraft Simulation using CesiumJS.

For collaboration, demos, or project discussions, feel free to contact Manya Technologies.

Scroll to Top