Support

STK-Python API Integration
STK has a variety of tools that can be integrated for automation and streamlining mission planning processes. Python is one of these tools. The STK installation includes a copy of Python and the necessary API for Integration.
Resources
-STK 12.8 or newer
-STK Python API
-Python Capable Code Editor (ex-PyCharm Community Edition)
Installation Guide
You need the STK Python API for your code to be able to interact with STK. To do this, we are going to use our Python command prompt. In this example, I will use Anaconda, which is included with the STK install.
Navigate to your preferred Python command prompt and run the following command.
Note: This is the default install location for STK, adjust as necessary depending on where you have installed it
Fundamental Code
Once you have installed the API into STK, you can begin to write Python code that will impact your STK scenario. First, you must make sure your code can call up STK.
To do this, you first must attach STK to your Python Code editor:
from agi.stk12.stkdesktop import STKDesktop
from agi.stk12.stkobjects import *
from agi.stk12.stkutil import *
stk = STKDesktop.AttachToApplication()
root = stk.Root
This code is necessary in all Python integration. It allows for your Python code to locate your STK instance and relay the code.
If STK is not already open, you can launch it from python with the following code by adding it to the previous code:
stk = STKDesktop.StartApplication(visible=True)
After that, we can create a new scenario using the following code:
root.NewScenario('New_Scenario')
scenario = root.CurrentScenario
scenario.SetTimePeriod('22 May 2024 04:00:00.000', '+24hr')
root.Rewind()
Note: You can set the strings to be anything you want, provided they are in the correct format, allowing you to change the name and the start/stop time for your scenario.
Add Elements with Connect
Another fundamental part of STK API is the connect command. Using the code below, you can send a Connect Command into STK. These commands are very valuable when developing. Getting Started with STK Connect Commands : LSAS Tec (freshdesk.com) is a resource to learn more about Connect Commands.
root.ExecuteCommand(“ Put a connect command here ”)
In this scenario, we will use connect commands to several details to the Scenario
First, we can add international borders by running the following command:
root.ExecuteCommand("VO * GlobeDetails MapDetail Show On Map RWDB2_Coastlines ShowDetail ON DetailColor yellow WindowID 1")
After that, let’s enable the flashlight in the 3D graphics window:
root.ExecuteCommand("VO * Lighting FlashlightShow On FlashlightGlobe On FlashlightObjects Off FlashlightLevel 100")
Next, we can write a series of connect commands to propagate some clouds and adjust their properties:
root.ExecuteCommand("VO * Attributes Clouds On 1")
root.ExecuteCommand("VO * Attributes Clouds Altitude 6000.0")
root.ExecuteCommand("VO * Attributes Clouds Roundness 0.50")
Finally we will maximize our 3D Graphics Display Window
root.ExecuteCommand('Window3d * Maximize 1')
Next Steps
You can run this code from your preferred Python code editor to allow Python to interact with STK and propagate a new scenario. You can write more code to automate the creation of objects and editing of your scenario. To learn specific examples of Aircraft and Satellite propagation using code in Python, please visit STK : LSAS Tec (freshdesk.com)
If you have any further questions or need assistance, we are here to help! Our dedicated Tec-Support team is ready to provide prompt and personalized assistance tailored to your needs. Please don't hesitate to reach out by submitting a ticket by going to https://lsas-tec.freshdesk.com/support/tickets/new. We look forward to assisting you and ensuring a positive experience.
Thanks,
LSAS Tec-Support Team
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article