Generating an API script from a selection
Description of how to generate an API script from a selection in Schematic Editor.
Generating a script
In Schematic Editor, an API script can be
generated from selection of components. By clicking the
Generate script from selection
option on the right-click menu (Figure 1),
the generated code is copied to the clipboard.
Generated code examples
An example of a selection is shown in Figure 2.
The generated code is split into 10 sections:
-
Parent assignment
# # Get the parent handle # try: # Cover property handlers (property_value_changed, property_value_edited...) parent = mdl.get_parent(container_handle) except: # Cover component handlers (init, pre_compile...) parent = mdl.get_parent(item_handle)
-
Removing created internal components function
def delete_created_inner_components(): # # Remove created components from parent # item_names = ["R1", "R2", "R3", "Junction1", "Junction2", "P2", "Electric Tag1", "Connection1", "Connection3", "Connection8", "Connection4", "Connection6", "Connection7", "Connection9"] for item_name in item_names: if mdl.exists(item_name, parent=parent): handle = mdl.get_item(item_name, parent=parent) mdl.delete_item(handle)
-
Removing all internal components function
def delete_all_inner_components(): # # Remove all components from parent # for connection in mdl.get_items(parent=parent, item_type=ITEM_CONNECTION): mdl.delete_item(connection) for junction in mdl.get_items(parent=parent, item_type=ITEM_JUNCTION): mdl.delete_item(junction) for component in mdl.get_items(parent=parent, item_type=ITEM_COMPONENT): mdl.delete_item(component) for item in mdl.get_items(parent=parent): mdl.delete_item(item)
-
Recreating components
# Components: # Component: R1 _r1 = mdl.create_component( type_name="core/Resistor", parent=parent, name="R1", position=(7512, 8064), size=(64, 32), layout="static" ) # Component: R3 _r3 = mdl.create_component( type_name="core/Resistor", parent=parent, name="R3", position=(7728, 8152), size=(64, 32), layout="static" ) # Component: R2 _r2 = mdl.create_component( type_name="core/Resistor", parent=parent, name="R2", position=(7912, 8064), size=(64, 32), layout="static" )
-
Recreating junctions
# Junctions: # Junction: Junction2 _junction2 = mdl.create_junction( name="Junction2", parent=parent, position=(7800, 8064) ) # Junction: Junction1 _junction1 = mdl.create_junction( name="Junction1", parent=parent, position=(7648, 8064) )
-
Recreating ports
# Ports: # Port: P2 _p2 = mdl.create_port( name="P2", parent=parent, label="", terminal_position=('right', 'auto'), flip=FLIP_HORIZONTAL, position=(8040, 8064) )
-
Recreating tags
# Tags: # Tag: Electric Tag1 _electric_tag1 = mdl.create_tag( value="tag", name="Electric Tag1", parent=parent, scope=TAG_SCOPE_LOCAL, position=(7376, 8064) )
-
Recreating comments
# Comments: # Comment: Comment1 _comment1 = mdl.create_comment( text="example comment", parent=parent, position=(7656, 7984) )
-
Recreating connections
# Connections: _connection1 = mdl.create_connection( start=_electric_tag1, end=mdl.term(_r1, "p_node"), name="Connection1", breakpoints=[] ) _connection6 = mdl.create_connection( start=mdl.term(_r3, "p_node"), end=_junction1, name="Connection6", breakpoints=[] ) _connection8 = mdl.create_connection( start=_junction2, end=mdl.term(_r2, "p_node"), name="Connection8", breakpoints=[] ) _connection4 = mdl.create_connection( start=mdl.term(_r1, "n_node"), end=_junction1, name="Connection4", breakpoints=[] ) _connection3 = mdl.create_connection( start=mdl.term(_r2, "n_node"), end=_p2, name="Connection3", breakpoints=[] ) _connection9 = mdl.create_connection( start=mdl.term(_r3, "n_node"), end=_junction2, name="Connection9", breakpoints=[] ) _connection7 = mdl.create_connection( start=_junction1, end=_junction2, name="Connection7", breakpoints=[] )
-
Disabling items that were disabled in selection
# Disable items: mdl.disable_items([ _r3, _connection6, _connection9, ])