Main Content

Building a Model Using Model Construction Commands

This section shows you how to use model construction commands to add blocks to your models and connect them.

Suppose you want to add a PI Section Line block and a Voltage Measurement block to your model, connect the + terminal of the Voltage Measurement block to the left end of the PI Section Line block, and connect the - terminal of the Voltage Measurement block to the right end of the PI Section Line block.

The following code shows you how to add and position the two blocks in your model.

add_block('powerlib/Elements/Pi Section Line','Mymodel/Block1');
add_block('powerlib/Measurements/Voltage Measurement', 

For each block you want to connect, you need to know the handles of the terminal ports.

Block1PortHandles = get_param('Mymodel/Block1','PortHandles');
Block2PortHandles = get_param('Mymodel/Block2','PortHandles');

The add_line command uses the RConn and Lconn fields of the Block1PortHandles and Block2PortHandles structure variables to connect the blocks. The RConn field represents the right connectors of the blocks and the Lconn field represents the left connectors. You then need to specify to the add_line command the indices of the connectors you want to connect.