Python Plugin Points

The Python plugin points allow you to specify a Python file to be used as a plugin. The benefit is that you do not have to worry about COM registration of the Active Scripting engine. The following plugins are available for Python:

Requirements

The Python plugin points require the following to be installed:

  • Local install of Python 3.x (at least version 3.6)
  • Install of the Python API. In the Programming help browse to Development Environments -> STK Python API.

Add the PATH environment variable

STK must link directly to the Python libraries. The Python directory containing python3.dll must be added to the PATH environment variable. If you are using Linux, the location of libpython3.so must be included in LD_LIBRARY_PATH. You must compile the Python installation with --enable-shared such that both libpython3.so and libpython3.y.so are available for linking. If libpython3.so is missing, reinstall Python as a shared library.

STK locates Python modules (including the STK Python API) following the rule that the Python interpreter uses. STK searches for the modules in the following order:

  1. PYTHONPATH environment variable
  2. A Python Virtual environment implemented using the venv module (virtual environments other than venv are not supported)
  3. PYTHONHOME environment variable
  4. PATH (or LD_LIBRARY_PATH on Linux) environment variable, searching for the first Python 3 installation

Upon instantiating a Python plugin, STK displays a message specifying the Python module search paths that are used.

Specify the plugin script in STK

Plugins specified at the application level (Access Constraints) and plugins specified within a scenario (all except Access Constraints) have different methods of specifying the Python script.

Application level plugins

Application level plugins must be configured before creating or loading the scenario.

  1. Desktop configuration
  2. Plugin scripts may be added or removed from the list of Access Constraints plugins. You can find that list under the Edit menu in Preferences -> Python Plugin.

  3. STK Object Model
  4. The STKPreferencesPythonPlugins method has been added to IAgStkPreferences, which returns a new interface IAgStkPreferencesPythonPlugins. This has a method AccessConstraintsPaths that returns a new interface, IAgPathCollection, from which you can Add or Remove plugin files.

  5. Connect
  6. Connect has an application level command PythonAccessConstraintPlugins with the Options being Add <file>, Remove <file>, and RemoveAll.

Scenario level plugins

Scenario level plugins are configured for each plugin point that is created within a scenario.

  1. Desktop Configuration
  2. Using Calculation Scalar as an example:

    1. Add a new Calculation Component in Analysis Workbench.
    2. Click the Select... button beside the Type field.
    3. Set the Type to Plugin.
    4. Set the Name to whatever you would like.
    5. Select Python in the Select Plugin Name field.
    6. Python is pre-registered and available.

    7. Click the Plugin Settings... button to select your script.
    8. When the script is selected, the plugin is instantiated. If there is a configuration, it is available under Properties.

  3. STK Object Model
  4. Using the STK Object Model, you can create and configure scenario level plugins. Using Calculation Scalar as an example, you can create the plugin with CreateCalcScalarPluginFromDisplayName method.

    CreateCalcScalarPluginFromDisplayName (<YourCalcScalarName>, <Description>, "Python")

    To select your plugin script, use the SetProperty method.

    SetProperty("Filename",<PathToPluginScript>)

    After selecting your plugin script, you can configure the attributes using the SetProperty method.

    SetProperty("Properties.<PropertyName>",<PropertyNewValue>)