Skip to content

SimulinkInterface is a Python utility that parses Simulink .slx files (ZIP/OPC containers) to extract rich block metadata—parameters, masks, ports, and subsystem hierarchies—and generates inline-embeddable, interactive SVGs that mimic the Simulink viewer with clickable nodes opening popups or a side panel for full block details.

License

Notifications You must be signed in to change notification settings

Mukund-Iyer/SimulinkInterface

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimulinkInterface

SimulinkInterface is a Python utility designed to parse Simulink model files (.slx). It extracts detailed block-level information, including parameters, masks, and subsystem hierarchies. It also has generates interactive SVG files that emulates Simulink model viewer.

Features

  • ✅ Parses .slx files to extract block attributes
  • ✅ Handles masked blocks and subsystem references
  • ✅ Cleans up temporary files automatically
  • ✅ Generates SVG files for all layers of model linked to each other.

Requirements

  • Python 3.10+
  • Install GraphViz (or) download GraphViz binaries, modify the Environment variable "Path" to include path to "bin" folder of the downloaded GraphViz binaries.
  • Uses other standard libraries such as: os, shutil, zipfile, xml.etree.ElementTree)

Usage

import SimulinkInterface
model = SimulinkInterface.SimulinkModel("path/to/simulink_model.slx")

Output Structure

A Python object will be created that contains the following:

  • block_list
  • connection_list

Each block in block_list is represented as a dictionary with keys such as:

  • Name, SID, BlockType, etc. (from XML attributes)
  • Parameters (Gain, SampleTime, etc.)
  • Mask details:
    • Mask_Type
    • Mask_Help
    • Mask_Parameter_*
  • Subsystem children (if any) under 'children' key
  • Connections of children under 'child_conns' key

Each connection in connection_list is basically a list of all connections between source and destination block in the top layer.

Apart from the object creation in code, a folder named 'output' will be created with several SVG files. The root.svg is the root of the Simulink model provided.

File Structure Expectations

The input Simulink file should be of extension .slx. Currently, this solution does not support .mdl files.

Temporary Folder

All extracted files are stored in a temporary folder named 'temp' located in the same directory as the script. This folder is automatically cleaned up when the object is deleted or undergoes garbage collection.

Example

import SimulinkInterface
model = SimulinkInterface.SimulinkModel("path/to/simulink_model.slx")
for block in model.block_list:
  print(block["Name"], block.get("Gain", "N/A"))

License

This project is licensed under the MIT License. This project also includes components developed by:

  • AT&T and the GraphViz community, which are licensed under the Eclipse Public License (EPL).

Please refer to the respective licenses for more details.

Note

The project has been shifted to GitLab and is being developed there. The newer versions can also find differences between two models. Let me know if you need the link for that.

03 November 2025: I rewrote the entire project in C++ (17). It has been committed to a new repository. This also contains comparison or diffing of two models. Please refer the link below to access it. Link: https://github.com/Mukund-Iyer/SAGE---Simulink-Analysis-and-Graph-Evaluation

About

SimulinkInterface is a Python utility that parses Simulink .slx files (ZIP/OPC containers) to extract rich block metadata—parameters, masks, ports, and subsystem hierarchies—and generates inline-embeddable, interactive SVGs that mimic the Simulink viewer with clickable nodes opening popups or a side panel for full block details.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages