2. Schematic Editor API

Module: typhoon.api.schematic_editor

Schematic API provides set of functions/methods to manipulate existing schematic models (tse files) and create new ones from scratch programmaticaly. This is most commonly used for creating scripts for testing and automating repetitive tasks, but its use is not restricted for these use cases only.

2.1. Examples

Following two examples illustrates how you can use Typhoon Schematic Editor API.

2.1.1. Example 1

This example illustrates creating model from scratch, saving it and compiling it as a last step.

from typhoon.api.schematic_editor import SchematicAPI

# Create SchematicAPI object
model = SchematicAPI()

# Create new model
model.create_new_model()

# Starting coordinates
x0 = 8192
y0 = 8192

# Component values
r_in_value = 100.0
l_value = 1e-5
r_value = 0.1
c_value = 5e-4

print("Creating scheme items...")
# Create Voltage Source component
v_in = model.create_component(
    "core/Voltage Source",
    name="Vin",
    position=(x0-300, y0),
    rotation="right"
)

# Create Resistor component
r_in = model.create_component(
    "core/Resistor",
    name="Rin",
    position=(x0-200, y0-100)
)

# Create Current Measurement component
i_meas = model.create_component(
    "core/Current Measurement",
    name="I",
    position=(x0-100, y0-100)
)

# Create Ground component
gnd = model.create_component(
    "core/Ground",
    name="gnd",
    position=(x0-300, y0+200)
)

# Create Inductor component
l = model.create_component(
    "core/Inductor",
    name="L",
    position=(x0, y0),
    rotation="right"
)

# Create Voltage Measurement component
v_meas = model.create_component(
    "core/Voltage Measurement",
    name="V",
    position=(x0+200, y0),
    rotation="right"
)

# Create RC Load Subsystem component
rc_load = model.create_component(
    "core/Empty Subsystem",
    name="RC Load",
    position=(x0+100, y0),
)

# Create port in Subsystem
p1 = model.create_port(
    name="P1",
    parent=rc_load,
    terminal_position=("top", "auto"),
    rotation="right",
    position=(x0, y0-200)
)

# Create port in Subsystem
p2 = model.create_port(
    name="P2",
    parent=rc_load,
    terminal_position=("bottom", "auto"),
    rotation="left",
    position=(x0, y0+200)
)

# Create Resistor component
r = model.create_component(
    "core/Resistor",
    parent=rc_load,
    name="R",
    position=(x0, y0-50),
    rotation="right"
)

# Create Capacitor component
c = model.create_component(
    "core/Capacitor",
    parent=rc_load,
    name="C",
    position=(x0, y0+50),
    rotation="right"
)

# Create necessary junctions
junction1 = model.create_junction(
    name="J1",
    position=(x0-300, y0+100),
)

junction2 = model.create_junction(
    name="J2",
    position=(x0, y0-100),
)

junction3 = model.create_junction(
    name="J3",
    position=(x0, y0+100),
)

junction4 = model.create_junction(
    name="J4",
    position=(x0+100, y0-100),
)

junction5 = model.create_junction(
    name="J5",
    position=(x0+100, y0+100),
)

# Connect all the components
print("Connecting components...")
model.create_connection(model.term(v_in, "p_node"), model.term(r_in, "p_node"))
model.create_connection(model.term(v_in, "n_node"), junction1)
model.create_connection(model.term(gnd, "node"), junction1)
model.create_connection(model.term(r_in, "n_node"), model.term(i_meas, "p_node"))
model.create_connection(model.term(i_meas, "n_node"), junction2)
model.create_connection(junction2, model.term(l, "p_node"))
model.create_connection(model.term(l, "n_node"), junction3)
model.create_connection(junction1, junction3)
model.create_connection(junction2, junction4)
model.create_connection(junction3, junction5)
model.create_connection(model.term(rc_load, "P1"), junction4)
model.create_connection(junction5, model.term(rc_load, "P2"))
model.create_connection(junction4, model.term(v_meas, "p_node"))
model.create_connection(model.term(v_meas, "n_node"), junction5)

model.create_connection(p1, model.term(r, "p_node"))
model.create_connection(model.term(r, "n_node"), model.term(c, "p_node"))
model.create_connection(model.term(c, "n_node"), p2)

# Set component parameters
print("Setting component properties...")
model.set_property_value(model.prop(r_in, "resistance"), r_in_value)
model.set_property_value(model.prop(l, "inductance"), l_value)
model.set_property_value(model.prop(r, "resistance"), r_value)
model.set_property_value(model.prop(c, "capacitance"), c_value)

# Save the model
file_name = "RLC_example.tse"
print("Saving model to '{}'...".format(file_name))
model.save_as(file_name)

# Compile model
if model.compile():
    print("Model successfully compiled.")
else:
    print("Model failed to compile")

# Close the model
model.close_model()

Script output:

Creating scheme items...
Connecting components...
Setting component properties...
Saving model to 'RLC_example.tse'...
Model successfully compiled.

After executing this script, model is saved in a file “RLC_example.tse in directory where script is located.

Following image shows how model looks like if opened in Typhoon Schematic Editor.

_images/rlc_example_pic.png

2.1.2. Example 2

This example ilustrates loading an existing model (created in previous example) and modyfing it, saving changes and compiling it as a last step.

from typhoon.api.schematic_editor import SchematicAPI

# Create SchematicAPI object
model = SchematicAPI()

# Load the model from file
print("Loading model...")
model.load("RLC_example.tse")

# Starting coordinates
x0 = 8192
y0 = 8192

print("Modifying model...")
# Get the handler for Rin component
r_in = model.get_item("Rin", item_type="component")
if r_in:
    # Delete the component
    model.delete_item(r_in)

# Get the handler for I component
i_meas = model.get_item("I", item_type="component")
if i_meas:
    # Delete the component
    model.delete_item(i_meas)

# Create a contactor component
switch = model.create_component(
    "core/Single Pole Single Throw Contactor",
    name="SW",
    position=(x0-200, y0-100)
)

# Get the component handlers to create connections with the contactor
v_in = model.get_item("Vin", item_type="component")
junction = model.get_item("J2", item_type="junction")

# Create the connections
model.create_connection(model.term(v_in, "p_node"), model.term(switch, "a_in"))
model.create_connection(model.term(switch, "a_out"), junction)

# Get the handler for RC Load subsystem
rc_load = model.get_item("RC Load", item_type="component")

# Get the handler for R component inside the RC Load subsystem
r = model.get_item("R", parent=rc_load, item_type="component")

# Read and change the resistor value of R component
old_r_value = model.get_property_value(model.prop(r, "resistance"))
new_r_value = old_r_value * 10
model.set_property_value(model.prop(r, "resistance"), new_r_value)

# Save the model
print("Saving model...")
model.save()

# Compile model
if model.compile():
    print("Model successfully compiled.")
else:
    print("Model failed to compile")

# Close the model
model.close_model()

Script output:

Loading model...
Modifying model...
Saving model...
Model successfully compiled.

2.2. Schematic API constants

Module: typhoon.api.schematic_editor.const

Various Schematic API method expects predefined constants for some of their parameters.

Below is a listing (Python module) of all constants which are used in Schematic API methods.

# This file is a part of Typhoon HIL API library.
#
# Typhoon HIL API is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
from __future__ import print_function, unicode_literals

# Icon rotate behavior constants.
ICON_ROTATE = "rotate"
ICON_NO_ROTATE = "no_rotate"
ICON_TEXT_LIKE = "text_like"

# Fully qualified name separator
FQN_SEP = "."

# Signal processing type constants.
SP_TYPE_INHERIT = "inherit"
SP_TYPE_INT = "int"
SP_TYPE_UINT = "uint"
SP_TYPE_REAL = "real"

# Kind constants.
KIND_SP = "sp"
KIND_PE = "pe"

# Direction constants.
DIRECTION_IN = "in"
DIRECTION_OUT = "out"

# Constants for specifying rotation.
ROTATION_DOWN = "down"
ROTATION_UP = "up"
ROTATION_LEFT = "left"
ROTATION_RIGHT = "right"

# Constants for specifying tag scopes.
TAG_SCOPE_LOCAL = "local"
TAG_SCOPE_GLOBAL = "global"
TAG_SCOPE_MASKED_SUBSYSTEM = "masked_subsystem"

# Constant for ItemHandle type
ITEM_HANDLE = "item_handle"

# Constants used for specifying item types.
ITEM_ANY = "unknown"
ITEM_COMPONENT = "component"
ITEM_CONNECTION = "connection"
ITEM_TAG = "tag"
ITEM_PORT = "port"
ITEM_COMMENT = "comment"
ITEM_JUNCTION = "junction"
ITEM_TERMINAL = "terminal"
ITEM_PROPERTY = "property"

# Constants used for specifying kind of error and/or warning.
ERROR_GENERAL = "General error"
ERROR_PROPERTY_VALUE_INVALID = "Invalid property value"

WARNING_GENERAL = "General warning"

# Constants used for specifying simulation method.
SIM_METHOD_EXACT = "exact"
SIM_METHOD_EULER = "euler"
SIM_METHOD_TRAPEZOIDAL = "trapezoidal"

GRID_RESOLUTION = 8

2.3. Positioning

Schematic scene coordinate system origin (0, 0) is in the top left corner of whole scene. Schematic scene size is 16k pixels (16384), so scheme scene center point will (8192, 8192).

2.4. Schematic model configuration

Schematic model configuration is manipulated with get_model_property_value and set_model_property_value methods. See API references section for detailed description of these two functions.

2.5. API references

class SchematicAPI(*args, **kwargs)

Class models schematic model and provide methods to manipulate schematic model.

close_model()

Closes model.

Parameters:None
Returns:None

Example:

#
# Demonstrate use of create_model() and close_model().
#

from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()

mdl.create_new_model(name="MyModel")

mdl.create_component(type_name="core/Resistor")

mdl.close_model()

Output


compile()

Compile schematic model.

Parameters:None
Returns:True if compilation was successful, False otherwise.

Example:

#
# Demonstrate use of compile function.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

volt_src = mdl.create_component("core/Voltage Source")
r = mdl.create_component("core/Resistor", name="R1")
con1 = mdl.create_connection(mdl.term(volt_src, "p_node"),
                            mdl.term(r, "p_node"))
con2 = mdl.create_connection(mdl.term(volt_src, "n_node"),
                             mdl.term(r, "n_node"))

# Save model
mdl.save_as("model.tse")

# Load and compile model
mdl.load("model.tse")
mdl.compile()

mdl.close_model()

Output


create_comment(text, parent=None, name=None, position=None)

Create comment with provided text inside the container component specified by parent.

Parameters:
  • text (str) – Comment text.
  • parent (ItemHandle) – Parent component handle.
  • name (str) – Comment’s name.
  • position (sequence) – X and Y coordinates of tag in the container.
Returns:

Handle for created comment.

Raises:

SchApiException in case when connection creation fails.

Example:

#
# Demonstrate use of create_comment function.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

# Create commment with some text
comment1 = mdl.create_comment("This is a comment")

#
# Create comment with text, custom name, and specified position
# in scheme.
#
comment2 = mdl.create_comment("This is a comment 2",
                                name="Comment 2",
                                position=(100, 200))

mdl.close_model()

Output


create_component(type_name, parent=None, name=None, rotation='up', position=None)

Creates component using provided type name inside the container component specified by parent. If parent is not specified top level parent (scheme) will be used as parent.

Parameter rotation expects respective constants as value (See Schematic API constants).

Parameters:
  • type_name (str) – Component type name, specifies which component to create.
  • parent (ItemHandle) – Container component handle.
  • name (str) – Component name.
  • rotation (str) – Rotation of the component.
  • position (sequence) – X and Y coordinates of component.
Returns:

Handle for created component.

Raises:

SchApiException in case when component creation fails.

Example:

#
# Demonstrate use of create_component function.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

# Create component at the top level scheme.
r = mdl.create_component(type_name="core/Resistor",
                           name="R1")

# Create subsystem component at the top level.
sub1 = mdl.create_component("core/Subsystem", name="Subsystem 1")

# Create inductor component inside previosuly created subsystem component.
inner_l = mdl.create_component(type_name="core/Inductor",
                                 parent=sub1,
                                 name="Inner inductor")

mdl.close_model()

Output


create_connection(start, end, name=None)

Create connection with specified start and end connectable handles. Connectable can be component terminal, junction, port or tag.

Note

Both start and end must be of same kind and they both must be

located in same parent.

Parameters:
  • start (ItemHandle) – Handle for connection start.
  • end (ItemHandle) – Handle for connection end.
  • name (str) – Connection name.
Returns:

Handle for created connection.

Raises:
  • SchApiException in case when connection creation fails.
  • SchApiDuplicateConnectionException in case when provided
  • connectables is already connected.

Example:

#
# Demonstrate use of create_connection function.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

#
# At the top level create two components, one junction and connect them.
#
#    |r|--------|j|------------|l|
#
r = mdl.create_component("core/Resistor")
j = mdl.create_junction(name="Junction 1")
l = mdl.create_component("core/Inductor")
con1 = mdl.create_connection(mdl.term(r, "n_node"), j)
con2 = mdl.create_connection(j, mdl.term(l, "p_node"))



#
# Create connection between tag and component (capacitor positive terminal
# named `n_node`).
#
tag1 = mdl.create_tag(value="A", name="Tag 1")
cap = mdl.create_component("core/Capacitor", name="Capacitor 1")
con3 = mdl.create_connection(tag1, mdl.term(cap, "n_node"))

#
# Create subsystem and inside one port and one component
# and connect them.
#
sub1 = mdl.create_component("core/Subsystem", name="Subsystem 1")
port1 = mdl.create_port(name="Port 1", parent=sub1)
super_cap = mdl.create_component("core/Super Capacitor",
                                 name="Super cap 1",
                                 parent=sub1)
con4 = mdl.create_connection(start=port1,
                             end=mdl.term(super_cap, "p_node"),
                             name="Inner connection")
print(con4)

mdl.close_model()

Output

connection: Subsystem 1.Inner connection
create_junction(name=None, parent=None, kind='pe', position=None)

Create junction inside container component specified by parent.

Parameter kind expects respective constants as value (See Schematic API constants).

Parameters:
  • name (str) – Junction name.
  • parent (ItemHandle) – Container component handle.
  • kind (str) – Kind of junction (can be signal processing or power electronic kind)
  • position (sequence) – X and Y coordinates of junction in the container.
Returns:

Handle for created junction.

Raises:

SchApiException in case when junction creation fails.

Example:

junction: Junction 1
junction: Junction 2
create_new_model(name=None)

Creates new model.

Parameters:name (str) – Optional model name, if not specified it will be automatically generated.
Returns:None

Example:

#
# Demonstrate use of create_model() and close_model().
#

from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()

mdl.create_new_model(name="MyModel")

mdl.create_component(type_name="core/Resistor")

mdl.close_model()

Output


create_port(name=None, parent=None, kind='pe', direction='out', sp_type='real', terminal_position=('left', 'auto'), rotation='up', hide_name=False, position=None)

Create port inside the container component specified by parent.

Parameters kind, direction, sp_type and and rotation expects respective constants as values (See Schematic API constants).

Parameters:
  • name (str) – Port name.
  • parent (ItemHandle) – Container component handle.
  • kind (str) – Port kind (signal processing or power electronic kind).
  • direction (str) – Port direction (applicable only for signal processing ports)
  • sp_type (str) – SP type for port.
  • terminal_position (tuple) – Specify position of port based terminal on component.
  • rotation (str) – Rotation of the tag.
  • hide_name (bool) – Indicate if label for terminal (created on component as a result of this port) should be hidden.
  • position (sequence) – X and Y coordinates of port.
Returns:

Handle for created port.

Raises:
  • SchApiException in case port creation fails (for example when
  • port is created at the top level parent or any other cause of
  • error).

Example:

#
# Demonstrate create_port function.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

#
# Port can't be created at the top level scheme (exception will be raised),
# so we need first to create subsystem in which port will be created.
#
sub1 = mdl.create_component(type_name="core/Subsystem", name="Subsystem 1")
port1 = mdl.create_port(parent=sub1, name="Port 1")

print(port1)

mdl.close_model()



Output

port: Subsystem 1.Port 1
create_tag(value, name=None, parent=None, scope='global', kind='pe', direction=None, rotation='up', position=None)

Create tag inside container component specified by parent handle..

Parameters scope, kind, direction and rotation expects respective constants as values (See Schematic API constants).

Parameters:
  • value (str) – Tag value, used to match with other tags.
  • name (str) – Tag name.
  • parent (ItemHandle) – Container component handle.
  • scope (str) – Tag scope, specifies scope in which matching tag is searched.
  • kind (str) – Kind of tag (can be either KIND_SP or KIND_PE).
  • direction (str) – Tag direction (for signal processing tags).
  • rotation (str) – Rotation of the tag, can be one of following: ROTATION_UP, ROTATION_DOWN, ROTATION_LEFT and ROTATION_RIGHT.
  • position (sequence) – X and Y coordinates of tag in the container.
Returns:

Handle for created tag.

Raises:

SchApiException in case when tag creation fails.

Example:

#
# Demonstrate use of create_tag function.
#
from typhoon.api.schematic_editor import SchematicAPI
from typhoon.api.schematic_editor import const

mdl = SchematicAPI()
mdl.create_new_model()

# Create tag with specified value and name.
tag1 = mdl.create_tag(value="A", name="Tag 1")


# Create second tag in subsystem, with custom scope, kind and direction.
sub1 = mdl.create_component("core/Subsystem")
tag2 = mdl.create_tag(parent=sub1,
                        value="B", name="Tag 2",
                        scope=const.TAG_SCOPE_LOCAL,
                        kind=const.KIND_SP,
                        direction=const.DIRECTION_OUT)

mdl.close_model()

Output


delete_item(item_handle)

Delete item named specified by item_handle.

Parameters:item_handle (ItemHandle) – Item handle.
Returns:None
Raises:SchApiException in case when deletion fails.

Example:

#
# Demonstrate use of delete_item function.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

# Create some items and then delete them.
r = mdl.create_component("core/Resistor")
j = mdl.create_junction()
tag = mdl.create_tag(value="Val 1")
sub1 = mdl.create_component("core/Subsystem")
inner_port = mdl.create_port(parent=sub1, name="Inner port1")

#
# Delete items
#
mdl.delete_item(r)
mdl.delete_item(j)
mdl.delete_item(tag)

# Delete subsystem
mdl.delete_item(sub1)

mdl.close_model()

Output


detect_hw_settings()

Detect and set hardware settings by querying hardware device.

Args:
None
Returns:
tuple (hw_product_name, hw_revision, configuration_id) or False if auto-detection failed.

Example:

#
#
#
from typhoon.api.schematic_editor import SchematicAPI

mdl = SchematicAPI()
mdl.create_new_model()

hw_sett = mdl.detect_hw_settings()

if hw_sett:
    print("HIL device was detected and model "
          "configuration was changed to {0}.".format(hw_sett))
else:
    print("HIL device autodetection failed, maybe HIL device is not connected.")

mdl.close_model()
disable_property(prop_handle)

Sets property as non-editable.

Note

The effect of this function is visible only on the Schematic Editor’s UI.

When the property is disabled, it is not possible to change its value in the dialog. To enable property, use enable_property() function.

Parameters:prop_handle (ItemHandle) – Property handle.
Returns:None

Example:

#
# Demonstrate use of disable_property, enable_property and is_property_enabled
# functions.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

# Create component
r = mdl.create_component("core/Resistor")

# Disable property
mdl.disable_property(mdl.prop(r, "resistance"))

# Check to see if property is enabled.
print(mdl.is_property_enabled(mdl.prop(r, "resistance")))

# Enable property
mdl.enable_property(mdl.prop(r, "resistance"))

print(mdl.is_property_enabled(mdl.prop(r, "resistance")))

mdl.close_model()

Output

False
True
disp_component_icon_text(comp_handle, text, rotate='text_like', size=10, relpos_x=0.5, relpos_y=0.5, trim_factor=1.0)

Specify text to be displayed inside component icon.

Parameters:
  • comp_handle (ItemHandle) – Component handle.
  • text (str) – Text to display.
  • rotate (str) – Constant specifying icon rotation behavior, (See Schematic API constants).
  • size (int) – Size of text.
  • relpos_x (float) – Center of text rectangle (on X axis).
  • relpos_y (float) – Center of text rectangle (on Y axis).
  • trim_factor (float) – Number in range (0.0 .. 1.0) which specifies at which relative width of text rectangle width to shorten text.
Returns:

None

Example:

#
# Demonstrate use of schematic API icon functions.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

tr1 = mdl.create_component("core/Three Phase Two Winding Transformer")
mdl.set_component_icon_image(tr1, "/path/to/image.png")

# Before text is written set color to red
mdl.set_color(tr1, "red")
mdl.disp_component_icon_text(tr1, "Sample text")

# Initiate update of component view on scene
mdl.refresh_icon(tr1)

mdl.close_model()

Output


enable_property(prop_handle)

Sets property as editable.

Note

The effect of this function is only visible on the Schematic Editor’s UI.

When the property is enabled, it is possible to change its value in the dialog. To disable property, use disable_property() function.

Parameters:prop_handle (ItemHandle) – Property handle.
Returns:None

Raises:

Example:

#
# Demonstrate use of disable_property, enable_property and is_property_enabled
# functions.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

# Create component
r = mdl.create_component("core/Resistor")

# Disable property
mdl.disable_property(mdl.prop(r, "resistance"))

# Check to see if property is enabled.
print(mdl.is_property_enabled(mdl.prop(r, "resistance")))

# Enable property
mdl.enable_property(mdl.prop(r, "resistance"))

print(mdl.is_property_enabled(mdl.prop(r, "resistance")))

mdl.close_model()

Output

False
True
error(msg, kind='General error', context=None)

Signals some error condition.

Parameters:
  • msg (str) – Message string.
  • kind (str) – Error kind constant.
  • context (ItemHandle) – Handle for context item.
Returns:

None

Example:

#
# Demonstrate use of error function.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

const = mdl.create_component("core/Constant", name="Constant 1")
mdl.error("Some error message about constant component", context=const)

mdl.close_model()

Output


exists(name, parent=None, item_type='unknown')

Checks if item named name is container in parent component specified by parent handle. If parent handle is not provided root scheme is used as parent.

Note

item_type is a constant which specify which item type to look for. See Schematic API constants.

Parameters:
  • name (str) – Item name to check.
  • parent (ItemHandle) – Parent handle.
  • item_type (str) – Item type constant.
Returns:

True if item with provided name exists in parent, False otherwise.

Example:

#
# Demonstrate use of exists_in function.
#
from typhoon.api.schematic_editor import SchematicAPI
from typhoon.api.schematic_editor import const

mdl = SchematicAPI()
mdl.create_new_model()

r = mdl.create_component("core/Resistor", name="R 1")
print(mdl.exists("R 1"))

sub1 = mdl.create_component("core/Subsystem")
inner_c = mdl.create_component("core/Capacitor", parent=sub1,
                                 name="Capacitor 1")
print(mdl.exists("Capacitor  1", sub1))

# Tests existence using filtering
sub2 = mdl.create_component("core/Subsystem", name="Sub 2")
mdl.create_port(name="Port 2", parent=sub2)

# Port creation also created terminal on Sub 2 subsystem
print(mdl.exists(name="Port 2",
                   parent=sub2,
                   item_type=const.ITEM_TERMINAL))


mdl.close_model()

Output

True
False
True
find_connections(connectable_handle1, connectable_handle2=None)

Return all connection handles which are connected to connectable_handle1.

If connectable_handle2 is also specified then return handles for shared connections (ones that are connecting connectable_handle1 and connectable_handle2 directly.

Parameters:
  • connectable_handle1 (ItemHandle) – Connectable handle.
  • connectable_handle2 (ItemHandle) – Other connectable handle.
Returns:

List of connection handles.

Raises:

SchApiItemNotFound if one or both connectables can’t be found.

Example:

#
# Demonstrate find_connections function.
#
from typhoon.api.schematic_editor import SchematicAPI
from typhoon.api.schematic_editor import const

mdl = SchematicAPI()
mdl.create_new_model()

const1 = mdl.create_component("core/Constant", name="Constant 1")
junction = mdl.create_junction(kind=const.KIND_SP, name="Junction 1")
probe1 = mdl.create_component("core/Probe", name="Probe 1")
probe2 = mdl.create_component("core/Probe", name="Probe 2")
con1 = mdl.create_connection(mdl.term(const1, "out"), junction)
con2 = mdl.create_connection(junction, mdl.term(probe1, "in"))
con3 = mdl.create_connection(junction, mdl.term(probe2, "in"))

#
# find_connections called with junction as connectable will return all three
# connections.
#
for connection_handle in mdl.find_connections(junction):
    print(connection_handle)

#
# To get only connection which connects junction and "Probe 2"
# find_connections is called with second parameter specified.
#
print("find_connection() specified with both connectables.")
for connection_handle in mdl.find_connections(junction,
                                              mdl.term(probe2, "in")):
    print(connection_handle)
    
mdl.close_model()

Output

connection: Connection2
connection: Connection1
connection: Connection3
find_connection() specified with both connectables.
connection: Connection3
fqn(*args)

Joins multiple provided arguments using FQN separator between them.

Parameters:*args – Variable number of string arguments.
Returns:Joined string.

Example:

#
# Demonstrate use of fqn function.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

parent_name = "Subsystem 1"
component_name = "Resistor 1"

comp_fqn = mdl.fqn(parent_name, component_name)
print(comp_fqn)


mdl.close_model()

Output

Subsystem 1.Resistor 1
get_component_type_name(comp_handle)

Return component type name.

Parameters:comp_handle (ItemHandle) – Component handle.
Returns:Component type name as string, empty string if component has not type (e.g. component is user subsystem).
Raises:SchApiItemNotFoundException if specified component can’t be found.

Example:

#
# Demonstrate use of get_component_type_name function.
#

from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

r = mdl.create_component("core/Resistor")
core_coupling = mdl.create_component("Single Phase Core Coupling")
sub = mdl.create_component("core/Subsystem")


for comp_handle in (r, core_coupling, sub):
    print("Component '{0}' has type '{1}'.".format(
        mdl.get_name(comp_handle),
        mdl.get_component_type_name(comp_handle)
    ))

Output

Component 'R1' has type 'pas_resistor'.
Component 'Core Coupling 1' has type 'Single Phase Core Coupling'.
Component 'Subsystem1' has type ''.
get_conv_prop(prop_handle, value=None)

Converts provided value to type which is specified in property type specification. If value is not provided property display value is used instead.

Parameters:
  • prop_handle (ItemHandle) – Property handle.
  • value (str) – Value to convert.
Returns:

Python object, converted value.

Raises:

SchApiException if value cannot be converted.

Example:

#
# Demonstrate use of get_conv_prop.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

r = mdl.create_component("core/Resistor", name="R1")
print(mdl.get_conv_prop(mdl.prop(r, "resistance"), "234"))

mdl.close_model()

Output

234.0
get_fqn(item_handle)

Get fully qualified name for item specified by item_handle.

Parameters:item_handle (ItemHandle) – Item handle.
Returns:Fully qualified name as string.

Example:

#
# Demonstrate use of get_fqn api function.
#
from typhoon.api.schematic_editor import SchematicAPI

mdl = SchematicAPI()
mdl.create_new_model()

r = mdl.create_component("core/Resistor", name="R1")
print(mdl.get_fqn(r))

sub = mdl.create_component("core/Subsystem", name="Sub1")
l = mdl.create_component("core/Inductor", name="L1", parent=sub)
print(mdl.get_fqn(l))

mdl.close_model()

Output

R1
Sub1.L1
get_hw_settings()

Get hardware settings from device without changing model configuration.

Parameters:None
Returns:
Tuple (hw_product_name, hw_revision, configuration_id) or
False if auto-detection failed.

Example:

#
# Demonstrate use of get_hw_settings.
#
from typhoon.api.schematic_editor import SchematicAPI

mdl = SchematicAPI()
mdl.create_new_model()

hw_sett = mdl.get_hw_settings()

if hw_sett:
    print("Hardware (product, revision, configuration) = {0}.".format(hw_sett))
else:
    print("Hardware settings read failed, maybe HIL device is not connected.")

mdl.close_model()
get_item(name, parent=None, item_type='unknown')

Get item handle for item named name from parent parent_handle.

Note

parent is optional if not specified root scheme will be used.

Note

item_type is optional parameter, it can be used to specify type of item to get handle of. It accepts constant which defines item type (See Schematic API constants)

Parameters:
  • name (str) – Item name.
  • parent (ItemHandle) – Parent handle.
  • item_type (str) – Item type constant.
Returns:

Item handle (ItemHandle) if found, None otherwise.

Raises:
  • SchApiException if there is multiple items found, for example
  • component has sub-component named exactly the same as component
  • terminal. In that case specify item_type to remove ambiguity.

Example:

#
# Demonstrate use of get_item function.
#
from typhoon.api.schematic_editor import SchematicAPI
from typhoon.api.schematic_editor import const

mdl = SchematicAPI()
mdl.create_new_model()

# Create one component on root level
r = mdl.create_component("core/Subsystem", name="R1")

# Get handle to component by using get_item
r2 = mdl.get_item(name="R1")

# Create subsystem with some items inside
sub1 = mdl.create_component("core/Subsystem", name="Sub 1")
c = mdl.create_component("core/Capacitor", name="C1", parent=sub1)
port1 = mdl.create_port(name="Port 1", parent=sub1)
port2 = mdl.create_port(name="Port 2", parent=sub1)

#
# Demonstrate get_item by filtering as un-filtered call will raise an exception
# because subsystem component now has terminals with same name as created ports.
#
port1_terminal_handle = mdl.get_item("Port 1", parent=sub1,
                                       item_type=const.ITEM_TERMINAL)
print(port1_terminal_handle)

mdl.close_model()

Output

terminal: Sub 1.Port 1
get_items(parent=None, item_type=None)

Return handles for all items contained in parent component specified using parent handle, optionally filtering items based on type, using item_type. item_type value is constant, see Schematic API constants for details.

Note

If parent is not specified top level scheme will be used as parent.

Note

Items are not recursively returned.

Parameters:
  • parent (ItemHandle) – Parent component handle.
  • item_type (str) – Constant specifying type of items. If not provided, all items are included.
Returns:

List of item handles.

Example:

#
# Example demonstrates use of get_items function.
#
from typhoon.api.schematic_editor import SchematicAPI
from typhoon.api.schematic_editor import const

mdl = SchematicAPI()
mdl.create_new_model()

r = mdl.create_component("core/Resistor", name="R1")
tag = mdl.create_tag(value="A", name="Tag 1")
sub1 = mdl.create_component("core/Subsystem", name="Subsystem 1")
inner_l = mdl.create_component("core/Inductor", parent=sub1,
                                 name="Inner inductor")
inner_port = mdl.create_port(name="Port 1", parent=sub1)
inner_sub = mdl.create_component("core/Subsystem",
                                   parent=sub1,
                                   name="Inner subsystem")

#
# As get_items was called without parent top level scheme items
# will be returned.
#
items = mdl.get_items()
for item in items:
    print(item)

#
# Following snippet demonstrates use of filtering with get_items
# function.
#
# Get all ports from subsystem referenced by sub1
items = mdl.get_items(parent=sub1, item_type=const.ITEM_PORT)
for item in items:
    print("Item is {0}.".format(item))
    print("Item name part is {0}.".format(mdl.get_name(item)))

mdl.close_model()

Output

component: R1
tag: Tag 1
component: Subsystem 1
Item is port: Subsystem 1.P1.
Item name part is P1.
Item is port: Subsystem 1.P2.
Item name part is P2.
Item is port: Subsystem 1.Port 1.
Item name part is Port 1.
get_model_property_value(prop_code_name)

Return value for specified model property (model configuration). Model property is identified by its code name which can be found in schematic editor schematic settings dialog when tooltip is shown over desired setting option.

Parameters:

prop_code_name (str) – Model property code name.

Returns:

Value for model property.

Raises:
  • SchApiItemNotFoundException if specified model property can’t be
  • found.

Example:

#
# Demonstrate use of get_model_property_value and set_model_property_value.
#
from typhoon.api.schematic_editor import SchematicAPI

mdl = SchematicAPI()
mdl.create_new_model()

# Let's print current hil device
print(mdl.get_model_property_value("hil_device"))

# Change show_modes model property to True
show_modes = mdl.get_model_property_value("show_modes")
print("Show modes before change is {0}.".format(show_modes))
mdl.set_model_property_value("show_modes", True)
show_modes = mdl.get_model_property_value("show_modes")
print("Show mode after change is {0}.".format(show_modes))

mdl.close_model()

Output

HIL402
Show modes before change is False.
Show mode after change is True.
get_name(item_handle)

Get name of item specified by item_handle.

Parameters:item_handle (ItemHandle) – Item handle.
Returns:Item name.

Example:

#
# Example demonstrates use of get_name function.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

sub = mdl.create_component("core/Subsystem", name="Subsystem 1")
r = mdl.create_component("core/Resistor", parent=sub, name="R1")

print(r)
r_name = mdl.get_name(r)
print(r_name)


mdl.close_model()

Output

component: Subsystem 1.R1
R1
get_ns_var(var_name)

Return value of namespace variable named var_name.

Parameters:var_name (str) – Namespace variable name.
Returns:Python object.
Raises:KeyError – if variable with given name doesn’t exist in the namespace.

Example:

#
# Demonstrate use of set_ns_var and get_ns_var functions.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()


# Create variable named 'var1'
mdl.set_ns_var("var1", 20)

print(mdl.get_ns_var("var1"))

# Update value vor variable 'var1'
mdl.set_ns_var("var1", 100)

print(mdl.get_ns_var("var1"))

mdl.close_model()

Output

20
100
get_ns_vars()

Get names of all variables in namespace.

Parameters:None
Returns:List of variable names in namespace.

Example:

#
# Demonstrate use of get_ns_vars.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

# Create some variables
mdl.set_ns_var("var1", 2.71)
mdl.set_ns_var("var2", 100)
mdl.set_ns_var("var3", "Hello")

#
# Print all variable names and their values.
#
for var_name in mdl.get_ns_vars():
    var_value = mdl.get_ns_var(var_name)
    print("Variable name is {0} and its value is {1}.".format(var_name,
                                                             var_value))

mdl.close_model()

Output

Variable name is var1 and its value is 2.71.
Variable name is var2 and its value is 100.
Variable name is var3 and its value is Hello.
get_position(item_handle)

Gets item position.

Parameters:item_handle (ItemHandle) – Item handle.
Returns:Position in tuple form (x, y).
Raises:SchApiItemNotFoundException when specified item can’t be found.

Example:

#
# Demonstrate use of get_position and set_position.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

# Get position of tag item
tag = mdl.create_tag(name="Tag 1", value="Tag value", position=(160, 240))
print("Tag position is {0}.".format(mdl.get_position(tag)))

# Set position
mdl.set_position(tag, (800, 1600))
print("New tag position is {0}.".format(mdl.get_position(tag)))

mdl.close_model()

Output

Tag position is [160, 240].
New tag position is [800, 1600].
get_property_combo_values(prop_handle)

Returns combo_values list for property specified by prop_handle.

Note

This function works for properties which have widget set to combo.

Parameters:prop_handle (ItemHandle) – Property handle.
Returns:Sequence of property combo values.
Raises:SchApiException if property widget is not combo.

Example:

#
# Demonstrate use of get_property_combo_values and set_property_combo_values
# functions.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

tr_line = mdl.create_component("core/Transmission Line", name="TR Line 1")

#
# Add new combo value to component property named model_def
#
model_def_handle = mdl.prop(tr_line, "model_def")
model_def_combo_values = mdl.get_property_combo_values(model_def_handle)
new_combo_values = model_def_combo_values + ["New option"]

# Set new combo values
mdl.set_property_combo_values(model_def_handle, new_combo_values)

mdl.close_model()

Output


get_property_default_value(prop_handle)

Returns property default value.

Parameters:prop_handle (ItemHandle) – Property handle.
Returns:Property default value as string.
Raises:SchApiItemNotFoundException if property can’t be found.

Example:

#
# Demonstrate use of get_property_default_value.
#
from typhoon.api.schematic_editor import SchematicAPI

mdl = SchematicAPI()
mdl.create_new_model()

r = mdl.create_component("core/Resistor", name="R1")
mdl.set_property_value(mdl.prop(r, "resistance"), 12.0)

res_value = mdl.get_property_value(mdl.prop(r, "resistance"))
def_value = mdl.get_property_default_value(mdl.prop(r, "resistance"))
print("Resistor '{0}' resistance value is '{1}'"
      " while its default value is '{2}'.".format(mdl.get_name(r),
                                                  res_value,
                                                  def_value))
mdl.close_model()

Output

Resistor 'R1' resistance value is '12.0' while its default value is '1'.
get_property_disp_value(prop_handle)

Return the display value of the property.

Parameters:prop_handle (ItemHandle) – Property handle.
Returns:str

Example:

#
# Demonstrate use of set_property_disp_value and get_property_disp_value
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

# Create component
const = mdl.create_component("core/Constant")

# Sets component property display value
mdl.set_property_disp_value(mdl.prop(const, "value"), 70)

# Print component property display value
print(mdl.get_property_disp_value(mdl.prop(const, "value")))

mdl.close_model()

Output

70
get_property_value(prop_handle)

Returns the value of a property.

Parameters:prop_handle (ItemHandle) – Property handle.
Returns:object

Example:

#
# Demonstrate use of set_property_value and get_property_value
# functions.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

const = mdl.create_component("core/Constant")

# Print current property value
print(mdl.get_property_value(mdl.prop(const, "value")))

# Sets new property value
mdl.set_property_value(mdl.prop(const, "value"), 20)
print(mdl.get_property_value(mdl.prop(const, "value")))

mdl.close_model()

Output

[1.0]
[20.0]
get_terminal_dimension(terminal_handle)

Returns the dimension of the component terminal.

Parameters:terminal_handle (ItemHandle) – Terminal handle.
Returns:Terminal dimension as list.

Example:

#
# Demonstrate use of get_terminal_dimension and set_terminal_dimension
# functions.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

const = mdl.create_component("core/Constant", name="Constant 1")
print(mdl.get_terminal_dimension(mdl.term(const, "out")))

mdl.set_terminal_dimension(mdl.term(const, "out"), (2,))
print(mdl.get_terminal_dimension(mdl.term(const, "out")))


mdl.close_model()

Output

calc
[2]
get_terminal_sp_type(terminal_handle)

Return component terminal SP type.

SP type can be one of the following: SP_TYPE_INHERIT, SP_TYPE_INT, SP_TYPE_UINT, SP_TYPE_REAL or the expression that can be evaluated into those values.

Parameters:terminal_handle (ItemHandle) – Terminal handle.
Returns:Terminal SP type as string.

Example:

#
# Demonstrate use of get_terminal_sp_type and get_terminal_sp_type_value.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

# Create component which calculates absolue value of input.
abs = mdl.create_component("core/Abs", name="Abs 1")

#
# Prints 'calc', this indicate that terminal sp type is calculated in
# calc_dimension handler.
#
print(mdl.get_terminal_sp_type(mdl.term(abs, "out")))

#
# Print inherit as input 'in' terminal inherit sp type from connected output
# terminal from other component.
#
print(mdl.get_terminal_sp_type(mdl.term(abs, "in")))

#
# get_terminal_sp_type_value returns actual calculated sp type for terminal.
# It is called in context when compiling was performed, as sp types are
# calulated after compile was started.
#

# Const 1 has 'real' sp type for 'out' terminal
const1 = mdl.create_component("core/Constant", name="Constant 1")

# Probe 'in' terminal has 'inherit' sp type
probe1 = mdl.create_component("core/Probe", name="Probe 1")
con = mdl.create_connection(mdl.term(const1, "out"),
                              mdl.term(probe1, "in"))

# After compile...

#
# Probe 'in' sp type is inherit from const1 component 'out' terminal which is
# real.
#
print(mdl.get_terminal_sp_type_value(mdl.term(probe1, "in")))

mdl.close_model()

Output

inherit
inherit
inherit
get_terminal_sp_type_value(terminal_handle)

Return component terminal calculated SP type (calculated based on value of SP type for that terminal).

If calculated, returned value can be either SP_TYPE_INT, SP_TYPE_UINT, SP_TYPE_REAL. Calculation of the SP type value is performed during the compilation of the schematic.

Parameters:terminal_handle (ItemHandle) – Terminal handle.
Returns:Terminal SP type as string.

Example:

#
# Demonstrate use of get_terminal_sp_type and get_terminal_sp_type_value.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

# Create component which calculates absolue value of input.
abs = mdl.create_component("core/Abs", name="Abs 1")

#
# Prints 'calc', this indicate that terminal sp type is calculated in
# calc_dimension handler.
#
print(mdl.get_terminal_sp_type(mdl.term(abs, "out")))

#
# Print inherit as input 'in' terminal inherit sp type from connected output
# terminal from other component.
#
print(mdl.get_terminal_sp_type(mdl.term(abs, "in")))

#
# get_terminal_sp_type_value returns actual calculated sp type for terminal.
# It is called in context when compiling was performed, as sp types are
# calulated after compile was started.
#

# Const 1 has 'real' sp type for 'out' terminal
const1 = mdl.create_component("core/Constant", name="Constant 1")

# Probe 'in' terminal has 'inherit' sp type
probe1 = mdl.create_component("core/Probe", name="Probe 1")
con = mdl.create_connection(mdl.term(const1, "out"),
                              mdl.term(probe1, "in"))

# After compile...

#
# Probe 'in' sp type is inherit from const1 component 'out' terminal which is
# real.
#
print(mdl.get_terminal_sp_type_value(mdl.term(probe1, "in")))

mdl.close_model()

Output

inherit
inherit
inherit
hide_property(prop_handle)

Makes component property invisible on the component’s dialog.

Note

The effect of this function is visible only in the Schematic Editor’s UI.

When this function is called, property will become invisible in the component’s dialog. To show a property, use hide_property() function.

Parameters:prop_handle (ItemHandle) – Property handle.

Example:

#
# Example demonstrates use of hide_property, show_property and
# is_property_visible functions.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

const = mdl.create_component(type_name="core/Constant")
print(mdl.is_property_visible(mdl.prop(const, "value")))

mdl.hide_property(mdl.prop(const, "value"))
print(mdl.is_property_visible(mdl.prop(const, "value")))

mdl.show_property(mdl.prop(const, "value"))
print(mdl.is_property_visible(mdl.prop(const, "value")))

mdl.close_model()

Output

True
False
True
info(msg, context=None)

Function signals informative messages.

Parameters:
  • msg (str) – Message string.
  • context (ItemHandle) – Handle for context item.
Returns:

None

Example:

#
# Demonstrate use of info function.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

r = mdl.create_component("core/Resistor", name="R1")
resistance_prop_handle = mdl.prop(r, "resistance")

resistance_value = mdl.get_property_value(resistance_prop_handle)
mdl.info("Resistor resistance is {0}".format(resistance_value),
                                             context=resistance_prop_handle)

mdl.close_model()

Output


is_property_enabled(prop_handle)

Returns True if property is enabled, False otherwise.

Parameters:prop_handle (ItemHandle) – Property handle.
Returns:bool

Example:

#
# Demonstrate use of disable_property, enable_property and is_property_enabled
# functions.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

# Create component
r = mdl.create_component("core/Resistor")

# Disable property
mdl.disable_property(mdl.prop(r, "resistance"))

# Check to see if property is enabled.
print(mdl.is_property_enabled(mdl.prop(r, "resistance")))

# Enable property
mdl.enable_property(mdl.prop(r, "resistance"))

print(mdl.is_property_enabled(mdl.prop(r, "resistance")))

mdl.close_model()

Output

False
True
is_property_visible(prop_handle)

Returns True if component property is visible on the component’s dialog, False otherwise.

Parameters:prop_handle (ItemHandle) – Property handle.
Returns:True if property is visible, False otherwise.

Example:

#
# Example demonstrates use of hide_property, show_property and
# is_property_visible functions.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

const = mdl.create_component(type_name="core/Constant")
print(mdl.is_property_visible(mdl.prop(const, "value")))

mdl.hide_property(mdl.prop(const, "value"))
print(mdl.is_property_visible(mdl.prop(const, "value")))

mdl.show_property(mdl.prop(const, "value"))
print(mdl.is_property_visible(mdl.prop(const, "value")))

mdl.close_model()

Output

True
False
True
is_subsystem(comp_handle)

Returns whether component specified by comp_handle is a subsystem (composite) component.

Note

Component is an atomic component if it’s not composite.

Parameters:comp_handle (ItemHandle) – Component handle.
Returns:True if component is subsystem, False otherwise.
Raises:SchApiItemNotFoundException if component is not found.

Example:

#
# Demonstrate use of is_component_composite function.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

r = mdl.create_component("core/Resistor")
sub1 = mdl.create_component("core/Subsystem")

print(mdl.is_subsystem(r))
print(mdl.is_subsystem(sub1))

mdl.close_model()

Output

False
True
is_terminal_feedthrough(terminal_handle)

Determine if terminal is feedthrough.

Parameters:terminal_handle (ItemHandle) – Terminal handle.
Returns:True if terminal is feedthrough, False otherwise.

Example:

#
# Demonstrate use of term function.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

# Create accumulator component, its out terminal is feedthrough
acc = mdl.create_component("core/Accumulator", name="Accummulator 1")
print(mdl.is_terminal_feedthrough(mdl.term(acc, "out")))

# Change feedthrough
mdl.set_terminal_feedthrough(mdl.term(acc, "out"), False)
print(mdl.is_terminal_feedthrough(mdl.term(acc, "out")))

mdl.close_model()

Output

True
False
load(filename, debug=True)

Loads model from file.

Parameters:
  • filename (str) – Filename in which model is located.
  • debug (bool) – Indicate to print messages or not.
Returns:

True if load was successful, False otherwise.

Example:

#
# Demonstrate load function.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

# Create model and save which will be loaded
mdl.create_component("core/Resistor")
mdl.save_as("new_model.tse")

# Load model
mdl.load("new_model.tse")

# Remove tse file to cleanup directory
os.remove("new_model.tse")

# Print items from model
for item in mdl.get_items():
    print(item)

mdl.close_model()

Output

component: R1
print_message(message)

Prints provided message if debug mode is activated.

Parameters:message (str) – Message to print.
Returns:None
prop(component, prop_name)

Create property handle.

Parameters:
  • component
  • prop_name
Returns:

Property handle.

Example:

#
# Demonstrate use of sch API prop function.
#

from typhoon.api.schematic_editor import SchematicAPI

mdl = SchematicAPI()
mdl.create_new_model()

r = mdl.create_component("core/Resistor", name="R1")
resistance_prop = mdl.prop(r, "resistance")

# Print value of resistor resistance property
resistance_value = mdl.get_property_value(resistance_prop)
print("Resistor '{0}' resistance is '{1}'.".format(mdl.get_name(r),
                                                  resistance_value))

mdl.close_model()

Output

Resistor 'R1' resistance is '1.0'.
refresh_icon(comp_handle)

Refresh component icon. Calls component DEFINE_ICON handler or top mask DEFINE_ICON if mask is present.

Parameters:comp_handle (ItemHandle) – Component handle.
Returns:None

Example:

#
# Demonstrate use of schematic API icon functions.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

tr1 = mdl.create_component("core/Three Phase Two Winding Transformer")
mdl.set_component_icon_image(tr1, "/path/to/image.png")

# Before text is written set color to red
mdl.set_color(tr1, "red")
mdl.disp_component_icon_text(tr1, "Sample text")

# Initiate update of component view on scene
mdl.refresh_icon(tr1)

mdl.close_model()

Output


save()

Save a loaded model into same file from which it is loaded.

Parameters:None
Returns:True if model is saved successfully, False otherwise.

Example:

#
# Demonstrate use of save and save_as functions.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

r = mdl.create_component("core/Resistor", name="R1")
c = mdl.create_component("core/Capacitor", name="C1")
con = mdl.create_connection(mdl.term(r, "n_node"),
                              mdl.term(c, "p_node"))

mdl.save_as("save_path.tse")

mdl.create_junction(name="Junction 1")

# Save changes
mdl.save()

mdl.close_model()

Output


save_as(filename)

Save schematic model under different name.

Parameters:filename (str) – Save schematic model using filename as new file name.
Returns:True if model is saved or False if some error occurs.

Example:

#
# Demonstrate use of save and save_as functions.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

r = mdl.create_component("core/Resistor", name="R1")
c = mdl.create_component("core/Capacitor", name="C1")
con = mdl.create_connection(mdl.term(r, "n_node"),
                              mdl.term(c, "p_node"))

mdl.save_as("save_path.tse")

mdl.create_junction(name="Junction 1")

# Save changes
mdl.save()

mdl.close_model()

Output


set_color(comp_handle, color)

Set color to be used in all subsequent icon API operations. Color name is specified as a string in format understood by Qt framework.

Parameters:
  • comp_handle (ItemHandle) – Component handle.
  • color (str) – Color name.
Returns:

None

Example:

#
# Demonstrate use of schematic API icon functions.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

tr1 = mdl.create_component("core/Three Phase Two Winding Transformer")
mdl.set_component_icon_image(tr1, "/path/to/image.png")

# Before text is written set color to red
mdl.set_color(tr1, "red")
mdl.disp_component_icon_text(tr1, "Sample text")

# Initiate update of component view on scene
mdl.refresh_icon(tr1)

mdl.close_model()

Output


set_component_icon_image(comp_handle, image_filename, rotate='rotate')

Specify image to be used in component icon. If component is masked, image for top mask icon is specified instead.

Parameters:
  • comp_handle (ItemHandle) – Component handle.
  • image_filename (str) – Image filename.
  • rotate (str) – Constant describing icon rotation behavior (See Schematic API constants).
Returns:

None

Example:

#
# Demonstrate use of schematic API icon functions.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

tr1 = mdl.create_component("core/Three Phase Two Winding Transformer")
mdl.set_component_icon_image(tr1, "/path/to/image.png")

# Before text is written set color to red
mdl.set_color(tr1, "red")
mdl.disp_component_icon_text(tr1, "Sample text")

# Initiate update of component view on scene
mdl.refresh_icon(tr1)

mdl.close_model()

Output


set_component_property(component, property, value)

Deprecated since version 2.0.

Use set_property_value() instead.

Sets component property value to provided value.

Parameters:
  • component (str) – Component name.
  • property (str) – Property name (code name of property, can be viewed in tooltip over property widget in component property dialog).
  • value (object) – New property value.
Returns:

True if property value was successfully applied, False otherwise.

set_hw_settings(product, revision, conf_id)

Deprecated since version 2.0.

Use set_model_property_value instead.

Sets new hardware settings.

Parameters:
  • product (str) – Product name (HIL 400, HIL 600 and so on).
  • revision (str) – Product revision (1, 2, …).
  • conf_id (str) – Configuration id.
Returns:

True if operation was successful, False otherwise.

set_model_property_value(prop_code_name, value)

Sets model property to specified value.

Parameters:
  • prop_code_name (str) – Model property code name.
  • value (object) – Value to set.
Returns:

None

Raises:
  • SchApiItemNotFoundException when specified model property doesn’t
  • exists.

Example:

#
# Demonstrate use of get_model_property_value and set_model_property_value.
#
from typhoon.api.schematic_editor import SchematicAPI

mdl = SchematicAPI()
mdl.create_new_model()

# Let's print current hil device
print(mdl.get_model_property_value("hil_device"))

# Change show_modes model property to True
show_modes = mdl.get_model_property_value("show_modes")
print("Show modes before change is {0}.".format(show_modes))
mdl.set_model_property_value("show_modes", True)
show_modes = mdl.get_model_property_value("show_modes")
print("Show mode after change is {0}.".format(show_modes))

mdl.close_model()

Output

HIL402
Show modes before change is False.
Show mode after change is True.
set_name(item_handle, name)

Set name for item.

Parameters:
  • item_handle (ItemHandle) – Item handle.
  • name (str) – Name to set.
Returns:

None

Raises:
  • SchApiItemNameExistsException if another item already has
  • provided name.
  • SchApiException in case when item pointed by item_handle doesn’t
  • have name attribute or if some other item already has provided name.

Example:

#
# Demonstrate use of set_name.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

probe = mdl.create_component("core/Probe", name="Probe 1")
print("Initial probe name is '{0}'.".format(mdl.get_name(probe)))

# Change name
mdl.set_name(probe, "Probe new name")

print("Name of probe after name change is '{0}'.".format(mdl.get_name(probe)))

mdl.close_model()

Output

Initial probe name is 'Probe 1'.
Name of probe after name change is 'Probe 1'.
set_ns_var(var_name, value)

Set namespace variable named var_name to value. If variable doesn’t exists in namespace, it will be created and value set.

Parameters:
  • var_name (str) – Namespace variable name.
  • value (object) – Value to be set.
Returns:

None

Example:

#
# Demonstrate use of set_ns_var and get_ns_var functions.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()


# Create variable named 'var1'
mdl.set_ns_var("var1", 20)

print(mdl.get_ns_var("var1"))

# Update value vor variable 'var1'
mdl.set_ns_var("var1", 100)

print(mdl.get_ns_var("var1"))

mdl.close_model()

Output

20
100
set_property_attribute(component, property, attribute, value)

NOTE: This function is deprecated. It is kept here, because some code exists which uses it.

Parameters:
  • component – component name.
  • property – property name.
  • attribute – attribute name.
  • value – new value for property.
Returns:

True if successful, False otherwise.

set_property_combo_values(prop_handle, combo_values)

Sets property combo values to provided one.

Note

Property specified by prop_handle must have widget set to combo.

Parameters:
  • prop_handle (ItemHandle) – Property handle.
  • combo_values (sequence) – Sequence of new combo values.
Returns:

None

Raises:
  • SchApiException when functions is called with property handle
  • where property widget is not combo.

Example:

#
# Demonstrate use of get_property_combo_values and set_property_combo_values
# functions.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

tr_line = mdl.create_component("core/Transmission Line", name="TR Line 1")

#
# Add new combo value to component property named model_def
#
model_def_handle = mdl.prop(tr_line, "model_def")
model_def_combo_values = mdl.get_property_combo_values(model_def_handle)
new_combo_values = model_def_combo_values + ["New option"]

# Set new combo values
mdl.set_property_combo_values(model_def_handle, new_combo_values)

mdl.close_model()

Output


set_property_disp_value(prop_handle, value)

Set property display value.

Parameters:
  • prop_handle (ItemHandle) – Property handle.
  • value (str) – Value.
Returns:

None

Example:

#
# Demonstrate use of set_property_disp_value and get_property_disp_value
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

# Create component
const = mdl.create_component("core/Constant")

# Sets component property display value
mdl.set_property_disp_value(mdl.prop(const, "value"), 70)

# Print component property display value
print(mdl.get_property_disp_value(mdl.prop(const, "value")))

mdl.close_model()

Output

70
set_property_value(prop_handle, value)

Set a new value to the property.

Parameters:
  • prop_handle (ItemHandle) – Property handle.
  • value (object) – New value.

Example:

#
# Demonstrate use of set_property_value and get_property_value
# functions.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

const = mdl.create_component("core/Constant")

# Print current property value
print(mdl.get_property_value(mdl.prop(const, "value")))

# Sets new property value
mdl.set_property_value(mdl.prop(const, "value"), 20)
print(mdl.get_property_value(mdl.prop(const, "value")))

mdl.close_model()

Output

[1.0]
[20.0]
set_simulation_method(simulation_method)

Deprecated since version 2.0.

Use set_model_property_value instead (simulation_method field in configuration object).

Set simulation method.

Parameters:simulation_method (str) – Method used for simulation.
Returns:True if successful, False otherwise.

Example:

#
# Demonstrate use of set_simulation_time and set_simulation_time_step functions.
#
from typhoon.api.schematic_editor import SchematicAPI
from typhoon.api.schematic_editor import const

mdl = SchematicAPI()
mdl.create_new_model()

mdl.set_simulation_method(const.SIM_METHOD_TRAPEZOIDAL)
mdl.set_simulation_time_step(100e-6)

mdl.close_model()

Output


set_simulation_time_step(time_step)

Deprecated since version 2.0.

Use set_model_property_value instead (simulation_time_step field in configuration object).

Set schematic model simulation time time_step.

Parameters:time_step (str) – Time step used for simulation.
Returns:True if successful, False otherwise.

Example:

#
# Demonstrate use of set_simulation_time and set_simulation_time_step functions.
#
from typhoon.api.schematic_editor import SchematicAPI
from typhoon.api.schematic_editor import const

mdl = SchematicAPI()
mdl.create_new_model()

mdl.set_simulation_method(const.SIM_METHOD_TRAPEZOIDAL)
mdl.set_simulation_time_step(100e-6)

mdl.close_model()

Output


set_terminal_dimension(terminal_handle, dimension)

Set component terminal dimension.

Parameters:
  • terminal_handle (ItemHandle) – Terminal handle.
  • dimension (tuple) – Terminal new dimension.

Example:

#
# Demonstrate use of get_terminal_dimension and set_terminal_dimension
# functions.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

const = mdl.create_component("core/Constant", name="Constant 1")
print(mdl.get_terminal_dimension(mdl.term(const, "out")))

mdl.set_terminal_dimension(mdl.term(const, "out"), (2,))
print(mdl.get_terminal_dimension(mdl.term(const, "out")))


mdl.close_model()

Output

calc
[2]
set_terminal_feedthrough(terminal_handle, feedthrough)

Set terminal feedthrough value.

Parameters:
  • terminal_handle (ItemHandle) – Terminal handle.
  • feedthrough (bool) – Terminal feedthrough value.
Returns:

None

Example:

#
# Demonstrate use of term function.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

# Create accumulator component, its out terminal is feedthrough
acc = mdl.create_component("core/Accumulator", name="Accummulator 1")
print(mdl.is_terminal_feedthrough(mdl.term(acc, "out")))

# Change feedthrough
mdl.set_terminal_feedthrough(mdl.term(acc, "out"), False)
print(mdl.is_terminal_feedthrough(mdl.term(acc, "out")))

mdl.close_model()

Output

True
False
set_terminal_sp_type(terminal_handle, sp_type)

Set component terminal SP (Signal processing) type.

SP type can be one of the constants for SP type (See Schematic API constants) or the expression that can be evaluated into those values.

Parameters:
  • terminal_handle (ItemHandle) – Terminal handle.
  • sp_type (str) – SP (Signal processing) type.

Example:

#
# Demonstrate use of set_terminal_sp_type and set_terminal_sp_type_value
# functions.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

#
# set_terminal_sp_type indirectly sets terminal sp type, terminal sp type
# resolver will in time of compilation calculate sp type value, which can
# be also set directly using set_terminal_sp_type_value (see example below)
#
const1 = mdl.create_component("core/Constant", name="Constant 1")
mdl.set_terminal_sp_type(mdl.term(const1, "out"), "int")

# set_terminal_sp_type_value directly sets value of terminal sp_type
mdl.set_terminal_sp_type_value(mdl.term(const1, "out"), "int")

mdl.close_model()

Output


set_terminal_sp_type_value(terminal_handle, sp_type_value)

Set component terminal SP type directly.

Parameters:
  • terminal_handle (ItemHandle) – Terminal handle.
  • sp_type_value (str) – New SP type value, must be constant for SP Type (See Schematic API constants).

Example:

#
# Demonstrate use of set_terminal_sp_type and set_terminal_sp_type_value
# functions.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

#
# set_terminal_sp_type indirectly sets terminal sp type, terminal sp type
# resolver will in time of compilation calculate sp type value, which can
# be also set directly using set_terminal_sp_type_value (see example below)
#
const1 = mdl.create_component("core/Constant", name="Constant 1")
mdl.set_terminal_sp_type(mdl.term(const1, "out"), "int")

# set_terminal_sp_type_value directly sets value of terminal sp_type
mdl.set_terminal_sp_type_value(mdl.term(const1, "out"), "int")

mdl.close_model()

Output


show_property(prop_handle)

Makes component property visible in the component’s dialog.

Note

The effect of this function is visible only on the Schematic Editor’s UI.

When this function is called, property will become visible in the component’s dialog. To hide a property, use hide_property() function.

Parameters:prop_handle (ItemHandle) – Property handle.
Returns:None

Example:

#
# Example demonstrates use of hide_property, show_property and
# is_property_visible functions.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

const = mdl.create_component(type_name="core/Constant")
print(mdl.is_property_visible(mdl.prop(const, "value")))

mdl.hide_property(mdl.prop(const, "value"))
print(mdl.is_property_visible(mdl.prop(const, "value")))

mdl.show_property(mdl.prop(const, "value"))
print(mdl.is_property_visible(mdl.prop(const, "value")))

mdl.close_model()

Output

True
False
True
sync_dynamic_terminals(comp_handle, term_name, term_num, labels=None, sp_types=None, feedthroughs=None)

Synchronize number of dynamic terminals on component with given name.

Parameters:
  • comp_handle (ItemHandle) – Component handle.
  • term_name (str) – Terminal name.
  • term_num (int) – Number of terminal to synchronize to.
  • labels (list) – List of labels for new terminals.
  • sp_types (list) – List of SP types for new terminals.
  • feedthroughs (list) – List of feedthrough values for new terminals.

Example:

#
# Demonstrate use of sync_dynamic_terminals function.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

sum = mdl.create_component("core/Sum", name="Sum 1")

# Increase number of dynamic terminal named 'in' from 2 to 10
mdl.sync_dynamic_terminals(sum, "in", 10)

# Decrease number of terminals back to 2
mdl.sync_dynamic_terminals(sum, "in", 2)

mdl.close_model()

Output


term(comp_handle, term_name)

Make a unique identity handle for some terminal. Used in place where terminal fqn is expected.

Parameters:
  • comp_handle (ItemHandle) – Component handle.
  • term_name (str) – Terminal name.
Returns:

Terminal handle.

Example:

#
# Demonstrate use of term function.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

r = mdl.create_component("core/Resistor", name="R1")
r_term_id = mdl.term(r, "n_node")
print(r_term_id)

sub = mdl.create_component("core/Subsystem", name="Subsystem 1")
c = mdl.create_component("core/Capacitor", name="C1")
c_term_id = mdl.term(c, "p_node")
print(c_term_id)

mdl.close_model()

Output

terminal: R1.n_node
terminal: C1.p_node
warning(msg, kind='General warning', context=None)

Signals some warning condition.

Parameters:
  • msg (str) – Message string.
  • kind (str) –
  • context (ItemHandle) – Handle for context item.
Returns:

None

Raises:

SchApiItemNotFoundException if context item can’t be found.

Example:

#
# Demonstrate use of warning.
#
from typhoon.api.schematic_editor import SchematicAPI
mdl = SchematicAPI()
mdl.create_new_model()

r = mdl.create_component("core/Resistor", name="R1")
resistance_prop_handle = mdl.prop(r, "resistance")

if mdl.get_property_value(resistance_prop_handle) < 0.0:
    mdl.warning(msg="Resistance value is negative",
                context=resistance_prop_handle)

mdl.close_model()

Output