STK Instance Experiments
我们已经在过去的3个Chapter中基本了解了STK的设计与工作模式
现在我们想找点实例,看看效果 👀
这一部分参考 STK Migration Guidance 和 STK Python Getting Started
实例来源
部分来自你安装STK时,内部自带的Code Samples
比如笔者的Code Samples在:
Bash |
---|
| C:\Program Files\AGI\STK 12\CodeSamples\CodeSamples
|

我的工作流
每当我想使用Python控制STK行为时,我会按如下的顺序去做
- 双击STK桌面图标,开启应用
-
在PowerShell中
Bash |
---|
| conda activate stk-exp
tasklist
|
找到对应的AgUiApplication.exe
的STK_PID
-
在虚拟环境中开启Spyder
去做
直接生成
我们先以这为例:
Bash |
---|
| C:\Program Files\AGI\STK 12\CodeSamples\CodeSamples\Automation\Python\Aviator_ObjectModel_FuelConsumptionStudy.py
|
效果:

交互式生成
再以这个为例:
Bash |
---|
| C:\Program Files\AGI\STK 12\CodeSamples\CodeSamples\Automation\Python\HohmannTransferUsingTargeter.py
|
效果:

卫星轨迹生成
示例来源: Python-STK 使用与交互
Python |
---|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 | from comtypes.client import CreateObject
from comtypes.gen import STKObjects
# 创建STK12桌面应用
stk = CreateObject("STK12.Application")
# STK11可见
stk.Visible = 1
# 获取IAgStkObjectRoot接口
root = stk.Personality2
# 查看root属性
root.NewScenario('sce_test')
# 让变量Sce获取场景句柄
Sce = root.CurrentScenario
# 创建sat0,sat1...sat7共8颗卫星
for num in range(0,8): #
SatObj = Sce.Children.New(18,'sat'+str(num))
SatIAF = SatObj.QueryInterface(STKObjects.IAgSatellite)
#查看当前卫星轨道预报模型
SatIAF.PropagatorType
# 其返回值为7,表示预报模型为二体模型(ePropagatorTwoBody)
ProIAF = SatIAF.Propagator
# 由IAgVePropagator跳转至IAgVePropagatorTwoBody
ProTwoBodyIAF = ProIAF.QueryInterface(STKObjects.IAgVePropagatorTwoBody)
# 设置卫星坐标系为J2000,轨道六要素为7000km,0,num×10°,0°,0°,0°
ProTwoBodyIAF.InitialState.Representation.AssignClassical(3,7000,0,num*10,0,0,0)
# 传递参数
ProTwoBodyIAF.Propagate()
# 保存Scenario2.sc文件(路径DIY)
root.SaveAs(r'C:\testSTK\Scenario2.sc')
# 保存Scenario2.vdf文件
root.SaveAs(r'C:\testSTK\Scenario2.vdf')
|
效果:
