Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.vscode
.ipynb_checkpoints
__pycache__
.gitattributes
.gitattributes

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ AGI's ready-to-use STK and ODTK families of products, enterprise software, and d

## What if I have questions about STK

Contact [email protected] with any questions regarding STK, STK Engine or any other AGI products.
Contact [email protected] with any questions regarding STK, STK Engine or any other AGI products.
31 changes: 31 additions & 0 deletions StkAutomation/python/FilterObjectsByType.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# --------------------------------------------------------------------
# demonstrates how to grab an array of all objects of a certain type
# with an optional string filter
#
# Author: aclaybrook
# Email: [email protected]
# --------------------------------------------------------------------
from comtypes.client import GetActiveObject

def filter_objects_by_type(objectType, name=''):
"""Returns a list of paths for the specified object type optionally filtered by a name string"""

# Only run if not already connected to STK
app = GetActiveObject('STK11.Application')
root = app.Personality2
xml = root.AllInstanceNamesToXML()

objs = xml.split('path=')
objs = objs[1:] # remove first string of '<'

objPaths = []
for i in range(len(objs)):
obji = objs[i].split('"')
objiPath = obji[1] # the 2nd string is the file path
objiSplit = objiPath.split('/')
objiClass = objiSplit[-2]
objiName = objiSplit[-1]
if objiClass.lower() == objectType.lower():
if name.lower() in objiName.lower():
objPaths.append(objiPath)
return objPaths
12 changes: 12 additions & 0 deletions StkAutomation/python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Python Automation

## Reviewed

- [x] FilterObjectsByType.py
- [ ] RealtimeMultipleObjs.ipynb
- [ ] AstrogatorOMWalkthroughPython.ipynb
- [ ] STK_OM_Tutorial/STK_OM_Tutorial.ipynb
- [ ] STK_OM_Tutorial/STK_OM_Tutorial_Complete.ipynb
- [ ] Astrogator_OM_Tutorial/Astrogator_OM_Tutorial.ipynb
- [ ] Astrogator_OM_Tutorial/Astrogator_OM_Tutorial_Completed.ipynb
- [ ] AnalyzerToPythonPlots/Analyzer Plotting and Data Analysis.ipynb
146 changes: 146 additions & 0 deletions StkAutomation/python/eventSub.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# --------------------------------------------------------------------
# demonstrates how to subscribe to STKObjectRoot Events using comtypes
#
# Author: jthompson
# Email: [email protected]
# --------------------------------------------------------------------
from comtypes.client import CreateObject, GetActiveObject, GetEvents, ShowEvents, PumpEvents
from comtypes.gen import STKObjects

class EventSink(object):
"""Class to sink to Events in STK"""
def IAgStkObjectRootEvents_OnAnimUpdate(self, this, epoch):
"""Animation Update Event"""
print("Animation epoch: " + str(epoch))

def IAgStkObjectRootEvents_OnScenarioNew(self, this, scenario):
"""New Scenario Event"""
print("Scenario new: " + scenario)

def IAgStkObjectRootEvents_OnScenarioLoad(self, this, scenario):
"""Scenario Load Event"""
print("Scenario load: " + scenario)

def IAgStkObjectRootEvents_OnScenarioClose(self, this):
"""Scenario Close Event"""
print("Scenario closed")

def IAgStkObjectRootEvents_OnScenarioSave(self, this, scenarioPath):
"""Scenario Save Event"""
print("Scenario saved to: " + scenarioPath)

def IAgStkObjectRootEvents_OnLogMessage(self, this, message, messageType, errorCode, fileName, lineNumber, displayId):
"""Log Message Created Event"""
print("Log Message")
print("\tMessage: " + message)
print("\tMessage type: " + str(messageType))
print("\tError code: " + str(errorCode))
print("\tFile name: " + fileName)
print("\tLine number: " + str(lineNumber))
print("\tDisplay ID: " + str(displayId))

def IAgStkObjectRootEvents_OnStkObjectAdded(self, this, sender):
"""Object Added Event"""
print("Object added: " + sender)

def IAgStkObjectRootEvents_OnStkObjectDeleted(self, this, sender):
"""Object Deleted Event"""
print("Object deleted: " + sender)

def IAgStkObjectRootEvents_OnStkObjectRenamed(self, this, sender, oldPath, newPath):
"""Object Renamed Event"""
print("Object renamed: " + sender)
print("\tOld Path: " + oldPath)
print("\tNew Path: " + newPath)

def IAgStkObjectRootEvents_OnAnimationPlayback(self, this, currentTime, action, direction):
"""Animation Playback Event"""
print("Animation playback")
print("\tCurrent time: " + str(currentTime))
print("\tAction: " + str(action))
print("\tDirection " + str(direction))

def IAgStkObjectRootEvents_OnAnimationRewind(self, this):
"""Animation Rewind Event"""
print("Animation rewind")

def IAgStkObjectRootEvents_OnAnimationPause(self, this, currentTime):
"""Animation Paused Event"""
print("Animation pause")
print("\tCurrent time: " + str(currentTime))

def IAgStkObjectRootEvents_OnScenarioBeforeSave(self, this, args):
"""Scenario Before Save Event"""
args = args.QueryInterface(STKObjects.IAgScenarioBeforeSaveEventArgs)
print("Before save")
print("\tContinue Save: " + str(args.ContinueSave))
print("\tPath: " + args.Path)

def IAgStkObjectRootEvents_OnAnimationStep(self, this, currentTime):
"""Animation Step Event"""
print("Animation step")
print("\tCurrent time: " + str(currentTime))

def IAgStkObjectRootEvents_OnAnimationStepBack(self, this, currentTime):
"""Animation Step Backward Event"""
print("Animation step back")
print("\tCurrent time: " + str(currentTime))

def IAgStkObjectRootEvents_OnAnimationSlower(self, this):
"""Animation Slower Event"""
print("Animation slower")

def IAgStkObjectRootEvents_OnAnimationFaster(self, this):
"""Animation Faster Event"""
print("Animation faster")

def IAgStkObjectRootEvents_OnPercentCompleteUpdate(self, this, args):
"""Percent Complete Update Event"""
args = args.QueryInterface(STKObjects.IAgPctCmpltEventArgs)
print("Percent complete update")
print("\tCan cancel: " + str(args.CanCancel))
print("\tCanceled: " + str(args.Canceled))
print("\tMessage: " + args.Message)
print("\tPercent completed: " + str(args.PercentCompleted))

def IAgStkObjectRootEvents_OnPercentCompleteEnd(self, this):
"""Percent Complete End Event"""
print("Percent complete end")

def IAgStkObjectRootEvents_OnPercentCompleteBegin(self, this):
"""Percent Complete Begin Event"""
print("Percent complete begin")

def IAgStkObjectRootEvents_OnStkObjectChanged(self, this, args):
"""Object Changed Event"""
args = args.QueryInterface(STKObjects.IAgStkObjectChangedEventArgs)
print("Object changed: " + args.Path)

def IAgStkObjectRootEvents_OnScenarioBeforeClose(self, this):
"""Scenario Before Close Event"""
print("Scenario before close")

def IAgStkObjectRootEvents_OnStkObjectPreDelete(self, this, args):
"""Object PreDelete Event"""
args = args.QueryInterface(STKObjects.IAgStkObjectPreDeleteEventArgs)
print("Object pre-delete")
print("\tContinue: " + str(args.Continue))
print("\tSender: " + args.Path)

### Testing Event Subscriptions

# Attach to STK 11 Application
app = GetActiveObject('STK11.Application')
root = app.Personality2

# Create EventSink
sink = EventSink()

# List all Events
ShowEvents(root, interface=STKObjects.IAgStkObjectRootEvents)

# Sink to all events in the EventSink class
connection = GetEvents(root, sink, interface=STKObjects.IAgStkObjectRootEvents)

# Defines a timeout necessary for COM
PumpEvents(100)