Scripting Tool

The Scripting Tool is a utility within Astrogator that enables you to write scripts in JScript, VBScript, Python, or MATLAB that will interact with object attributes, calculation object components, and custom-defined parameters. You can find the tool on sequences and backward sequences, on differential corrector and plugin search profiles, and also as a standalone profile on target sequences. Use the Scripting Tool to perform a variety of functions to augment the logic of the Mission Control Sequence.

As a stand-alone profile, use it as an initial guess tool to set control values inside the target sequence, based on calculation objects, before refining the control values by a differential corrector, optimizer, or plugin search profile.

When the scripting tool is attached to a search profile, use it to map an independent variable to segments in the target sequence. For instance, use it to force two maneuvers to use the same Delta-V value, where that value is solved for by the search profile.

You can also use the Scripting Tool to make sequences and backward sequences more generic by exposing a parameter that is used in multiple places in the sequence. You only need change the parameter in one place in the sequence and the Scripting Tool will push the value into all places that it is used. Also, on a repeating sequence or backward sequence, the Scripting Tool can make the sequence use different values on each iteration.

Using the Scripting Tool

To create a script using the Scripting Tool, first select the Enabled check box to activate the tool, and then add and define the object attributes, calculation object components, and parameters that you want the script to interact with.

Click to place a copy of the script — including the object attributes, calculation object components, and parameters defined for it — on the clipboard. Click to replace the current script with a copy of the one currently on the clipboard.

Each time you run the script, Astrogator produces a summary report of it that includes the initial value of its object attributes, calculation object components, and parameters and the final values of the object attributes. Click to view this report.

Scripting toolbar

You can add, copy, delete, and perform other actions on object properties, calculation objects, and parameters by right-clicking in the table that lists them or by using the following toolbar buttons:

Button Name Function
Properties... Opens a properties window that lists all object properties, calculation objects, and parameters defined for the script. You can modify advanced properties of individual object properties, calculation objects, and parameters from this window.
New... Inserts a new object property, calculation object, or parameter with default properties settings.
Cut Removes the currently selected object property, calculation object, or parameter from the list and copies it to the clipboard.
Copy Makes a copy of the currently selected object property, calculation object, or parameter to the clipboard.
Paste Inserts a copy of the object property, calculation object, or parameter that is currently on the clipboard.
Delete Deletes the currently selected object property, calculation object, or parameter.

Object properties

The script will be able to use and change object properties assigned to it. For each property, choose the Object that contains the property. All segments nested within the sequence in which the Scripting Tool is located are available for selection. For stand-alone Scripting Tool profiles, other profiles in the same Target Sequence are also available.

Next, choose the Attribute that corresponds to the property that the script will use and/or change. The attributes of each object are described in detail in the Connect documentation. To choose an attribute that is read-only, for example, the estimated burn duration of an impulsive maneuver, set the ReadOnlyProperty to true; otherwise, only attributes that are editable are available. If the attribute is a quantity, select the Unit in which the script will interact with the value. Finally, give the object property a Name; you can then use this name as a variable in the script.

Calc objects

The script will be able to use the values of calculation objects that are assigned to it. For each component, select the calculation object that the script needs to be able to access and edit its properties.

In the properties window, double-click the Calc Object field to bring up an Embedded Component Link Selection window and configure the calculation object. Click Change... to select a calculation object from the Component Browser. You can use the button to copy the currently selected calculation object to the clipboard and the button to replace the current calculation object with a copy of the one that is on the clipboard. Click to save a copy of the current calculation object to the Component Browser. Click OK or Cancel to accept or reject the changes you have made and return to the properties window.

If the calculation object gives a quantity, select the Unit in which the script will get the value. Finally, give the calculation object a Name; you can then use this name as a variable in the script.

The calculation objects are evaluated at the initial state of the sequence in which the scripting tool is located. To get a calculation object evaluated at a different state, use the Value at Segment calculation object located in the Segments folder.

Parameters

You can use seven types of parameters in a script: Boolean, Date, Double, Enumeration, Integer, Quantity, and String. Each parameter appears on a separate line with Name, Value, Unit, Type, Dimension, and User Comment fields. Use the Name field to identify the parameter and as a variable in the script. Use the User Comment field to give the parameter a reference description. The Value, Unit, and Dimension fields are all dependent on the parameter's type and are defined in the table below.

Parameter Type Properties Configuration
Boolean Value can be true or false. Dimension and Unit are disabled.
Date Value can be any date. Dimension is disabled and fixed to DateFormat. Unit can be any date format supported by STK. You can also set minimum and maximum values for the parameter in the properties window.
Double Value can be any real number. Dimension and Unit are disabled. You can also set minimum and maximum values for the parameter in the properties window.
Enumeration Value can be any value in the enumeration. The enumeration can be defined in the EnumChoices field using the properties window. Dimension and Unit are disabled.
Integer Value can be any integer. Dimension and Unit are disabled. You can also set minimum and maximum values for the parameter in the properties window.
Quantity Value can be any real number. Dimension can be any unit type supported by STK. Unit can be any unit of the selected Dimension that is supported by STK.You can also set minimum and maximum values for the parameter in the properties window.
String Value can be any character string. Dimension and Unit are disabled.

Inheriting parameters

If you have scripts attached to two or more search profiles within the same target sequence, you can pass the value of a double, quantity, or date parameter from one search profile to the next by selecting the Inherit check box. The Inherit field appears in the parameters of all search profile scripts after the first search profile of a target sequence. The field is active if you give the parameter a name and type that is the same as a parameter in a previous search profile and if that profile is active and the attached script is enabled. If you set a parameter to inherit its value, then the Value, Unit, and Type fields are inactive.

When you apply corrections to the target sequence, Astrogator will clear the Inherit field so that the script does not reinitialize the parameter the next time that it runs and write over the value that you applied.

Script

After you have selected and defined the object attributes, calculation objects, and parameters that you want to make available to the script, select the scripting language from the Language drop-down menu and enter the script in the space beneath. The object attributes, calculation objects, and parameters are all available as variables in the script, using the same names that they have in the lists above. In the script, the variables are initialized to the value of the object properties, calculation objects, and parameters in the units associated with them, if applicable. Setting the value of a variable associated with an editable object property in the script will set the object property to that value in the MCS, in the specified unit of the object property, if applicable.

The variable type of object properties depends on the property. If the property refers to a numerical quantity, the variable will represent a real number in the specified unit. If the property refers to a Boolean, such as the Active flag of a stopping condition, then the variable is also a Boolean in the script. If the property refers to a component, such as an engine model, the variable is a string that corresponds to the name of the component. To set the property to a different component, assign the variable to a string with the name of the new component to use. Other object properties that represent strings, such as a property with a drop-down list of choices, are also treated as strings in the script.

Object property and calculation object variables that refer to dates are either treated as numbers or strings depending on the unit type of the variable. If the unit type is EpSec, EpMin, EpHr, EpDay, EpYr, JDate, ModJDate, JDateOff, YYDDD, YYYYDDD, JED, EarthEpTU, SunEpTU, or GPSZ, it is treated as a number; otherwise it is treated as a string.

Special variables

Besides the attributes and calculation objects visible in the respective drop-down menus of the Scripting Tool, there is a selection of special variables that are available to the scripts that you write using it.

Variable Definition
iteration Enter the iteration count of the sequence segment that contains the script.
abortMCS Stops the run of the MCS. This defaults to false; if true after the script runs, the MCS stops.
root Enter the STK Object Model root/starting point for the API. Available for VBScript and Python only.

Parameters and Search Profiles

You can use parameters defined for a script as control variables for search profiles in a Target Sequence. By default, the following rules apply to parameters of scripts nested within a Target Sequence:

  • Parameters in a sequence or backward sequence within a Target Sequence are available to search profiles assigned to that Target Sequence.
  • Parameters in a Scripting Tool Profile are available to search profiles assigned to the immediate parent Target Sequence.
  • Parameters in a script defined for a search profile are available to that search profile.

If you select the Allow target sequences to use nested target sequence controls and results MCS Option check box, then parameters of scripts nested anywhere within a Target Sequence are available to all parent Target Sequences.

Python Scripting Tool

Module imports

Python 3.6+ and the STK Python API are required to use the Python Scripting Tool.

When doing an import from the Python Scripting tool, a local module is imported from local directories in this order:

  1. <Python install folder>
  2. <scenario folder>
  3. <STK user area>/Config/Scripting/Python
  4. <STK all users area>/Scripting/Python
  5. <STK install folder>/STKData/Scripting/Python
Directory Description
<Python install folder> Python installation directory
<scenario folder> Scenario directory
<STK user area> STK user's directory
<STK all users area> Directory that contains STK application data for all users
<STK install folder> STK installation directory

Edits to the local module will not be reflected in STK unless you restart STK.

STK does not support all module locations when creating a VDF. If you need a VDF with the module, then place the module in the scenario directory or subdirectory. Once this is done, you can enable the option to import Scenario files when creating the VDF.

Global variables

Unlike VBScript, each Python script operates in its own namespace, so variables defined in one script will not be available in another. However, imported modules are shared across all Python environments, so it is possible to share global state between scripts using modules. STK provides a simple module for facilitating global state in <STK Install Folder>/STKData/Scripting/Python/globals.py. This module contains a dictionary for storing global state, and is available for any script to import.

Here is an example for storing global state:

`from globals import cache`
`cache["my_shared_number"] = 1`
		

Here is an example using global state in another script:

`from globals import cache`		
`shared_num = cache["my_shared_number"]`		
		

Attempting to assign to a module import will fail, like the following example:

`from globals import cache`		
'cache = my_shared_object  #Resets local variable "cache" only, will not persist!`