Creating and Animating Aircraft in STK Engine with Python

stk-aircraft-simulation-manya-technologies

Systems Tool Kit (STK) is widely used for modeling, simulating, and visualizing aerospace and defense scenarios. With STK Engine, you can embed STK’s 2D/3D visualization inside your own applications and fully control it programmatically.

In this blog, we’ll see how to:

  • Create multiple aircraft in STK Engine using Python
  • Display them in 2D and 3D views
  • Control simulation animation (start, pause, reset)
  • Switch seamlessly between map (2D) and globe (3D) modes

Prerequisites

  • STK Engine 12 installed with Python bindings (agi.stk12.stkengine)
  • Basic knowledge of Python and Tkinter for GUI

Python Code

Below is a simplified example. It creates 5 aircraft with random routes over India, displays them in a Tkinter window, and lets you control animation and views.

import random
from tkinter import Tk, BOTH, LEFT, Button, Frame, StringVar, OptionMenu
from agi.stk12.stkengine import *
from agi.stk12.stkengine.tkcontrols import GlobeControl, MapControl

# --- Start STK Engine ---
stk = STKEngine.StartApplication(noGraphics=False)
root = stk.NewObjectRoot()
root.NewScenario("Aircraft_Simulation")

# Function to create aircraft with two waypoints
def create_aircraft(name, lat1, lon1, alt1, lat2, lon2, alt2):
    aircraft = root.CurrentScenario.Children.New(1, name)   # 1 = Aircraft
    route = aircraft.Route
    route.Method = 0  # Great circle
    wp1 = route.Waypoints.Add()
    wp1.Latitude, wp1.Longitude, wp1.Altitude = lat1, lon1, alt1
    wp1.Speed = 0.1
    wp2 = route.Waypoints.Add()
    wp2.Latitude, wp2.Longitude, wp2.Altitude = lat2, lon2, alt2
    wp2.Speed = 0.1
    route.Propagate()
    return aircraft

# Create 5 aircraft randomly in India
aircraft_names = []
for i in range(5):
    lat1, lon1, alt1 = random.uniform(8, 30), random.uniform(68, 90), random.uniform(5, 15)
    lat2, lon2, alt2 = lat1 + random.uniform(5, 10), lon1 + random.uniform(5, 10), alt1 + random.uniform(0, 5)
    name = f"AC_{i+1}"
    create_aircraft(name, lat1, lon1, alt1, lat2, lon2, alt2)
    aircraft_names.append(name)

# --- Tkinter GUI ---
window = Tk()
window.title("STK Engine Aircraft Simulation")
window.geometry("1200x700")

# Animation controls
def start_animation(): root.ExecuteCommand('Animate * Start')
def stop_animation(): root.ExecuteCommand('Animate * Pause')
def reset_animation(): root.ExecuteCommand('Animate * Reset')

# Zoom to selected aircraft
def zoom_aircraft():
    ac = selected_ac.get()
    root.ExecuteCommand(f'VO * ViewFromTo Normal From */Aircraft/{ac}')

# Home view centered on India
def zoom_home():
    globeControl.SetViewCenterPoint(22.0, 80.0)

# Toggle between 2D and 3D
is_3d = False
def toggle_view():
    nonlocal_vars = {'is_3d': is_3d}
    if nonlocal_vars['is_3d']:
        globeControl.pack_forget()
        mapControl.pack(fill=BOTH, expand=True, side=LEFT)
        toggle_btn.config(text="Switch to 3D")
        nonlocal_vars['is_3d'] = False
    else:
        mapControl.pack_forget()
        globeControl.pack(fill=BOTH, expand=True, side=LEFT)
        toggle_btn.config(text="Switch to 2D")
        nonlocal_vars['is_3d'] = True

# --- Top Buttons ---
controls = Frame(window)
controls.pack(fill=BOTH, pady=5)

Button(controls, text="▶ Start", width=10, command=start_animation).pack(side=LEFT, padx=3)
Button(controls, text="⏸ Pause", width=10, command=stop_animation).pack(side=LEFT, padx=3)
Button(controls, text="⏮ Reset", width=10, command=reset_animation).pack(side=LEFT, padx=3)
Button(controls, text="🏠 Home", width=10, command=zoom_home).pack(side=LEFT, padx=3)

selected_ac = StringVar(window)
selected_ac.set(aircraft_names[0])
OptionMenu(controls, selected_ac, *aircraft_names).pack(side=LEFT, padx=3)
Button(controls, text="🔍 Zoom AC", width=12, command=zoom_aircraft).pack(side=LEFT, padx=3)

toggle_btn = Button(controls, text="Switch to 3D", width=12, command=toggle_view)
toggle_btn.pack(side=LEFT, padx=3)

# --- Visualization frame ---
view_frame = Frame(window)
view_frame.pack(fill=BOTH, expand=True)
globeControl = GlobeControl(view_frame)
mapControl = MapControl(view_frame)
mapControl.pack(fill=BOTH, expand=True, side=LEFT)  # start in 2D

# Start simulation
root.ExecuteCommand('Animate * Reset')
root.ExecuteCommand('Animate * Start')

window.mainloop()

# Cleanup
root.CloseScenario()
stk.ShutDown()

Key Features

  • Aircraft creation: Each aircraft has two waypoints defining a route across India.
  • Animation control: Start, pause, and reset scenario time with a click.
  • Zoom: Quickly center the camera on any aircraft.
  • 2D/3D toggle: Switch seamlessly between map view and 3D globe view.

Output

When you run the script:

  • A Tkinter window opens with control buttons at the top.
  • The main area displays either 2D map or 3D globe depending on toggle.
  • Aircraft move along their paths while you control simulation time.

This setup is perfect for building custom mission planning GUIs, training simulators, or control panels powered by STK Engine.

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.

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

Scroll to Top