Skip to content

Commit 545b2c2

Browse files
committed
Making engine example cross platform compatible (linux and windows)
1 parent 6430081 commit 545b2c2

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

StkEngineApplications/Python/PythonEngineExample.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import os
12
import time
2-
from agi.stk12.stkengine import STKEngine
3-
from agi.stk12.stkdesktop import STKDesktop
3+
import platform
4+
45
from agi.stk12.stkobjects import *
56
from agi.stk12.stkutil import *
67

@@ -9,13 +10,18 @@
910
"""
1011
SET TO TRUE TO USE ENGINE, FALSE TO USE GUI
1112
"""
12-
useStkEngine = False
13-
13+
if platform.system() == "Linux":
14+
# Only STK Engine is available on Linux
15+
useStkEngine = True
16+
else:
17+
# Change to true to run engine on Windows
18+
useStkEngine = False
1419
############################################################################
1520
# Scenario Setup
1621
############################################################################
1722

1823
if (useStkEngine):
24+
from agi.stk12.stkengine import STKEngine
1925
# Launch STK Engine with NoGraphics mode
2026
print("Launching STK Engine...")
2127
stk = STKEngine.StartApplication(noGraphics = True)
@@ -24,14 +30,15 @@
2430
stkRoot = stk.NewObjectRoot()
2531

2632
else:
33+
from agi.stk12.stkdesktop import STKDesktop
2734
# Launch GUI
2835
print("Launching STK...")
2936
stk = STKDesktop.StartApplication(visible = True, userControl = True)
3037

3138
# Get root object
3239
stkRoot = stk.Root
3340

34-
# Set date format
41+
# Set date format
3542
stkRoot.UnitPreferences.SetCurrentUnit("DateFormat", "UTCG")
3643

3744
# Create new scenario
@@ -227,7 +234,16 @@
227234

228235
# Add US shapefile to bounds
229236
bounds = coverageDefinition.Grid.Bounds
230-
bounds.RegionFiles.Add(r'C:\Program Files\AGI\STK 12\Data\Shapefiles\Countries\United_States_of_America\United_States_of_America.shp')
237+
238+
if platform.system() == "Linux":
239+
install_path = os.getenv("STK_INSTALL_DIR")
240+
else:
241+
import winreg
242+
registry = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
243+
key = winreg.OpenKey(registry, r'Software/AGI/STK/12.0')
244+
install_path = winreg.QueryValueEx(key, "InstallHome")
245+
246+
bounds.RegionFiles.Add(os.path.join(install_path, r'Data/Shapefiles/Countries/United_States_of_America\United_States_of_America.shp'))
231247

232248
# Set resolution
233249
grid.ResolutionType = AgECvResolution.eResolutionDistance

0 commit comments

Comments
 (0)