How to call a script BEFORE opening a Simulink subsystem?

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!

답변 (1개)

Sebastian Castro
Sebastian Castro 2014년 10월 2일

1 개 추천

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

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.
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 .

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Subsystems에 대해 자세히 알아보기

제품

질문:

2014년 10월 2일

댓글:

2014년 10월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by