Clear Filters
Clear Filters

Redraw/update block mask within a custom Simulink library

13 views (last 30 days)
Hi MathWorks community,
I am trying to solve a task that probably is rather easy, but I have not manged to finde a solution yet I really hope it is not just a case of me not being able to use google.
I am working with a custom Simulink library. On the top layer of that library I added an empty subsystem/block with a mask that displays information regarding the current version of the library: the save date and who it was saved by. My code in the "Icon & Ports" part of the Mask Editor looks as follows:
% Library path:
path = which(bdroot);
% Save date:
libDir = dir(path);
dateNum = libDir.datenum;
format = 'dd-mmm-yyyy HH:MM';
% Saved by:
libInfo = Simulink.MDLInfo(path);
% Dispaly Version Information of Library:
text(0.5,0.2,['{\fontsize{8}{\itSave date: }',datestr(dateNum, format),...
' // {\itSaved by: }',libInfo.LastModifiedBy,'}'],...
'horizontalAlignment','center','verticalAlignment','middle','texmode','on');
This all works perfectly fine, the only probnlem is, that the text/mask does not automatically update after I saved the library. I have to either close and open the whole library again, or open and close the mask editor so that the mask is redrawn.
I know that I can creat a PostSaveFcn Callback for either the sinbgle block or the whole liobrary, but I have no clue what function I should call. Is there something like a "redraw" command for a single block or an "update masks" function for a library?
Thanks in advance for your comments and help :)
Benedikt

Answers (1)

Chaitanya Krishna Kantambhatla
I Understand that you are trying to update the mask after you save.
You can try the following ways to refresh your Library browser.
  • You can use the sl_refresh_customizations command in the ‘PostSaveFcn’ Callback which refreshes any customization involved in the current MATLAB session
  • Alternately, you can also use Simulink.LibraryDictionary.refresh function which updates the Simulink Library dictionary dependencies.
  • In case you are working with Simulink models, and you want to update the custom library blocks, you can use the following command that refreshes the model and updates the mask diagram in the model, also updating the library blocks.
set_param(<your model>,'SimulationCommand','Update')
  1 Comment
Benedikt
Benedikt on 20 Sep 2022
First of all thank you very much for your response and please excuse my late reaction!
Yes, I'm trying to update the mask of a block after I saved my library. But sadly the three proposed solutions didn't work for me.
  • Regarding the first two: I tried these functions both in the ‘PostSaveFcn’ Callback of the library itself as well as the block whose mask I would like to update. But both didn't do anything. I might have to read more into the documentation, because I have also not fully understood theses functions yet - but so far it seems like they are not suited for what I want to do.
  • The third option doesn't apply for me, since the block is only part of the library. I tried this command anyways, but of course that resulted in an error. But I guess this command does the same as the hotkey combination "Ctrl + D" while working on a simulink model.
In any case, thank you very much.

Sign in to comment.

Categories

Find more on Interactive Model Editing in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!