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:
- PYTHONPATH environment variable
- A Python Virtual environment implemented using the venv module (virtual environments other than venv are not supported)
- PYTHONHOME environment variable
- 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.
- Desktop configuration
- STK Object Model
- Connect
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.
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.
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.
- Desktop Configuration
- Add a new Calculation Component in Analysis Workbench.
- Click the Select... button beside the Type field.
- Set the Type to Plugin.
- Set the Name to whatever you would like.
- Select Python in the Select Plugin Name field.
- Click the Plugin Settings... button to select your script.
- STK Object Model
Using Calculation Scalar as an example:
Python is pre-registered and available.
When the script is selected, the plugin is instantiated. If there is a configuration, it is available under Properties.
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>)