Python Custom Block

Define this block with Python commands and functions.

The PyCustomBlock block provides a generic interface for specifying the block's properties and defining its simulation function based on OML commands and functions. The simulation function is specified in Python code and stored as a block parameter. The Python code is used during simulation.
  1. From the Palette Browser, select Activate > CustomBlocks > PyCustomBlock. Drag the block into your diagram and double-click it.
    The block dialog appears with tabs to define the Ports, States, Parameters, SimFunction and other advanced properties for the block.
  2. On the Ports tab, enter the number of input and output ports for the block, enter a name for each port, then click OK.
  3. On the States tab, enter the state of the block with respect to its initial continuous condition, initial state derivative, initial discrete state, and number of initial object states, then click OK.
  4. On the Parameters tab, enter the number of parameters for the block. For each parameter, enter a name, value, and type, then click OK.
  5. On the SimFunction tab, generate a code skeleton, enter the simulation function for your block, then click OK. The skeleton provides the essential framework for the Python function that handles the interface with inputs, outputs and events.
  6. On the Advanced tab, enter the number of modes and zero-crossings for the block, select the activation mode: always active, initially active or standard, then click OK.