slQuery

easy-as-pie API to Simulink
50 Downloads
Updated 10 Aug 2021

Editor's Note: This file was selected as MATLAB Central Pick of the Week

slQuery - the "easy-as-pie" API to Simulink

slQuery is a "slickness-layer" ontop of the find_system and get/set_param API-functions and various related features of Simulink. It resulted from several inconveniences i had to deal with, while writing scripts that interact with and modify model structures.

slQuery brings you two major tools that make scripted interaction with models very easy and clean.

  1. slQuery is a query language inspired by CSS/jQuery, XPath and regex that allows searching a Simulink model for groups of blocks that satisfy certain conditions and relations to each other.

  2. slQuery wraps arrays of Simulink block handles into lightweight "proxy objects" that can be used to access block parameters and structural features in a syntactically pleasing way.

Have a look: This small example script shows how to interact with a model using slQuery. It acts on the two plain blocks given on the left side and step-by-step transforms them to become the Simulink logo on the right.

But this only the beginning! For a detailed description of what slQuery allows you to do, go to the documentation and reference pages section.

Installation

slQuery is implemented as a crazily compact single class file, that you just put onto the MATLAB search path somewhere. You can download and install the script in your local scripts folder using the following command.

websave(fullfile(uigetdir, '/slQuery.m'), 'https://raw.githubusercontent.com/arinar/slQuery/master/slQuery.m')

This will give you all the slQuery-features.

To also have the documentation and tests available locally, clone this repositiory or download the .zip and then use the pathtool command to add it to the MATLAB search path.

Bugs or Contributions

Report bugs or missing features of slQuery as well as ideas or code via the project page on github.

Or contact me directly via robert with a circle-a then raschhour followed by the dotcom.

slQuery and TargetLink

At my job, I've been working with the dSPACE TargetLink production code generator a lot. slQuery is to a great extent the result of me recognizing and refining best practices and code patterns for an efficient automation of tedious modelling tasks. Scripting is often the only feasible way to handle systematic changes to our code generation basis models. The TargetLink block data API is in my opinion just as not-slick as the Simulink API and so, more expressive means of interacting with this data were needed as well. Therefore TargetLink has a special place in slQuery's heart.

Both the query language and proxy object magic do support access and manipulation of the TargetLink block data. This access is made possible via the special [tl.〈tab〉.〈prop〉=...] parameters in the query and .tl.〈tab〉.〈prop〉 subscript syntax of the wrapper objects.

slQuery's baby sister project ddQuery provides a similar tooling for the TargetLink Data Dictionary, which is oftentimes even more useful in this context.

Cite As

Robert Rasche (2024). slQuery (https://github.com/arinar/slQuery), GitHub. Retrieved .

MATLAB Release Compatibility
Created with R2022b
Compatible with R2017b to R2022b
Platform Compatibility
Windows macOS Linux
Categories
Find more on Component-Based Modeling in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Versions that use the GitHub default branch cannot be downloaded

Version Published Release Notes
1.10.0.1

* line-connect features
* setop-support (like union, ..., ismember) on objects
* eval for block parameter evaluation
* positioncenter, positionsize for position calucations
* pure-ascii library link combinators
* model and subsystem reference support

1.10.0

* line-connect features
* setop-support (like union, ..., ismember) on objects
* eval for block parameter evaluation
* positioncenter, positionsize for position calucations
* pure-ascii library link combinators
* model and subsystem reference support

1.9.0

* fix/add combinator "=" support for phyiscal signal routing
* fix `sel`: now excludes current system (only selected blocks inside
gcs)
* support Two Way Conn blocks in "~>" and "=>" combinators
* better indexing subsasgn by reusing subsref code

1.8.0

* explicit text for hyperlink
* more special port chars in combinator portspecs
* `.sel`-method for instantly wrapping selected blocks in current system
* numeric subsref works for any shape result (X.LineHandles.Outport(1) gives all 1st lines)

1.7.0

add colon-operator for retrieving port- and line-handles of blocks
add basic support for Simscape physical connection modelling
add support for TargetLink properties in query-syntax

1.5.0

ability to reference block parameters of previous selectors
more flexible port/line retrieval with colon-operator

1.4.0

To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.