Sub-libraries do not appear in the library browser
Show older comments
I'm finding that using the instructions from Simulink>User's Guide>Managing Blocks>Working with Block Libraries>Creating Block Libraries to create sub-libraries, these sub-libraries are not shown in the library browser. Is this to be expected and do I need to customise the library browser to have them displayed?
Accepted Answer
More Answers (2)
Phil Taylor
on 15 Nov 2012
Edited: Phil Taylor
on 15 Nov 2012
Tested on R2012a
I've also been struggling to get separate library files to appear as children of another library. Firstly, I followed the documentation, but that only shows how to add multiple top-level libraries. In the end I found the solution in the Simscape libraries' slblocks.m files.
A number of things to note:
- Every library must have an slblocks.m file. Don't change the name of it either.
- For children libraries you will need to create a folder to hold the mdl file and the slblocks.m file. The library can have any (unique) name you want. The folder must be added to the path.
- Every slblocks.m file on the path is automatically read by the Library Browser when you refresh it (F5). So you never need to run these files explicitly to test them.
- Every child library will have to be linked into the parent library using the subsystem OpenFcn technique described in the documentation. Because they are uniquely named and on the path you don't need any relative path, just use open_system('name_of_library');
The following example assumes 2 child libraries in one top-level library.
The solution for both children is the same. Setup the Browser struct in each slblocks.m as follows:
Browser(1).Library = 'child_n_library_mdl_name'; % n = 1, 2, etc.
Browser(1).Name = 'Text name of child_n'; % n = 1, 2, etc.
Browser(1).PanelIcon = 'some_image.jpg';
Browser(1).IsTopLevel = 0;
blkStruct.Browser = Browser;
The solution for the top level library is to setup the Browser struct in slblocks.m as follows:
Browser(1).Library = 'top_level_library_mdl_name';
Browser(1).Name = 'Text name of top level';
Browser(1).Type = 'Palette';
Browser(1).Children = { 'Text name of child_1', ...
'Text name of child_2', }; % and so on
blkStruct.Browser = Browser;
(Note, always use Browser(1), don't think you need to put Browser(2) for the second child; remember that each slblocks.m represents its own library object according to the Library Browser.)
After doing this for all your top-level and children libraries you should have them appear in the Library Browser (with icons if you've included them) in a true hierarchical fashion. You can also mix true subsystems and separate library subsystems in the same top-level library. I assume you could extend this functionality to lower-level sublibraries by adding a Children field to any of your Children libraries' Browser structs, but I haven't tried that myself.
Nigel
on 17 Aug 2011
0 votes
Categories
Find more on Creating Custom Components and Libraries in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!