Configuration Manager API¶
Module: typhoon.api.configuration_manager
The Configuration Manager API contains a set of functions to create new and manipulate existing project configurations.
Example¶
The following example demonstrates the entire functionality of the configuration manager API.
In this example, a project is first loaded from an existing .tcp file. Then a configuration is loaded from an existing .tcfg file. With handles to these loaded items, the configuration is changed by selecting the possible options in the projects configuration. Once this is done, the project configuration can be generated.
#
# Demonstrate use of load_project function
#
from typhoon.api.configuration_manager import ConfigurationManagerAPI
from os.path import join, dirname, realpath
# Get path to the assets dir, which will hold all required files.
assets_path = join(dirname(realpath(__file__)), "assets")
print(assets_path)
cfg_manager = ConfigurationManagerAPI()
project_handle = cfg_manager.load_project(join(assets_path, "project-file.tcp"))
#
# Load configuration from file and generate output using it.
#
config1 = cfg_manager.load_config(join(assets_path, "config1.tcfg"))
# Generate output model based on configuration specified by 'config1'.
generate_result = cfg_manager.generate(project_handle, config1)
print("Output model is located in file: '{}'".format(
generate_result.generated_schematic_path)
)
#
# Create another configuration from scratch (using API).
#
config2 = cfg_manager.create_config("Config2")
cfg_manager.picks(config2,
[cfg_manager.make_pick("Rectifier", "Thyristor Rectifier"),
cfg_manager.make_pick("Motor", "Induction machine squirrel",
{
"enb_sig_out": "True",
"load_src": "Model"
})])
# Generate output model based on configuration specified by 'config2'.
generate_result = cfg_manager.generate(project_handle, config2)
print("Output model is located in file: '{}'".format(
generate_result.generated_schematic_path)
)
# Also, configuration created using API (in memory) can be saved for later use.
config3 = cfg_manager.create_config("Config3")
print("Created configuration named '{0}'".format(cfg_manager.get_name(config3)))
cfg_manager.picks(config3, [cfg_manager.make_pick("Rectifier",
"Thyristor Rectifier")])
cfg_manager.save_config(config3, "config3.tcfg")
# End.
Script output:
C:\GIT\t_api\build\doc_build\api_doc\configuration_manager_api_examples\assets
Output model is located in file: 'C:\GIT\t_api\build\doc_build\api_doc\Config managment example project_Config 1.tse'
Output model is located in file: 'C:\GIT\t_api\build\doc_build\api_doc\Config managment example project_Config2.tse'
Created configuration named 'Config3'