How to call a script BEFORE opening a Simulink subsystem?

3 views (last 30 days)
When the user double clicks a Simulink subsystem, I would like to call a MATLAB .m script (to check if the block is a disabled library link, and issue a warning if the associated model file is not "locked" in the version control system), and then open the subsystem normally.
  • By using the OpenFcn callback, I can only call the script INSTEAD of opening the subsystem.
  • When I write an OpenFcn callback that calls the script and then calls open_system to open the subsystem, I get an error message which says I must not call OpenFcn recursively.
I'm using MATLAB version 2012b.
Any ideas would be appreciated!

Answers (1)

Sebastian Castro
Sebastian Castro on 2 Oct 2014
Kurt,
I'd like to step back a little, if that's okay.
1. There is a display option on Simulink models that visual cues (badges) based on library links status. To access it, you can select Display > Library Links from the Simulink menu.
2. Alternatively, you could always run a model-wide check to test for disabled library links. You could write your own by searching through using the find_system function, or you can use built-in Model Advisor (Analysis > Model Advisor > Model Advisor) and run some of these checks.
Best, Sebastian
  2 Comments
Kurt Fischle
Kurt Fischle on 2 Oct 2014
Hi Sebastian, thanks for your answer! My problem is that I would like to display the warning as soon as possible when the user disables a link and forgets to lock the associated file.
Ideally, I would run the check immediately whenever a link is disabled; but as far as I know, Simulink does not provide a hook or callback for that event.
So my idea was to run the check whenever the user double clicks on a subsystem - which normally happens pretty often during editing.
Sebastian Castro
Sebastian Castro on 2 Oct 2014
Well, how about this?
You can create a mask for your Subsystem block (right-click, select Mask > Create Mask ).
In the Initialization tab, you can add the following code:
Then, when your links are disabled you'll actually get a warning pop-up dialog! However, this won't be immediately when you open the block -- this will happen when the model updates before simulation, or when you hit Simulation > Update Diagram .

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!