Customize Library Browser Appearance

Reorder Libraries

A library’s name and sort priority determines its order in the tree view of the Library Browser. Libraries appear in ascending order of priority. Libraries that have the same priority are sorted alphabetically.

The Simulink library has a sort priority of -1 by default. All other libraries have a sort priority of 0 by default. These sort priorities cause the Simulink library to display first in the Library Browser by default.

You can reorder libraries by changing their sort priorities. To change library sort priorities, add code in this form to an sl_customization.m file on the MATLAB® path:

cm.LibraryBrowserCustomizer.applyOrder({'LIBNAME1',PRIORITY1, ...
                                        'LIBNAME2',PRIORITY2, ...
                                         .
                                         .
                                        'LIBNAMEN',PRIORITYN});

LIBNAMEn is the name of the library (or its model file) and PRIORITYn is an integer indicating the library's sort priority. For example, this code moves the Simulink® Extras library to the top of the Library Browser’s tree view.

cm.LibraryBrowserCustomizer.applyOrder({'Simulink Extras',-2});

After adding or modifying the sl_customization.m file, enter sl_refresh_customizations at the MATLAB command prompt to see the customizations take effect.

For more information on the customization functions, see Registering Customizations.

Disable and Hide Libraries

To disable or hide libraries, sublibraries, or library blocks, insert code in this form in an sl_customization.m file (see Registering Customizations) on the MATLAB path. Blocks that you hide in a library also do not appear on the quick insert menu that you invoke in the model.

cm.LibraryBrowserCustomizer.applyFilter({'Item1','State', ...
                                         'Item2','State', ...
                                         .
                                         .
                                         'ItemN','State'});
  • ItemN is the library, sublibrary, or block to disable or hide. Specify the item in the form 'LibraryName/Sublibrary/Block'.

    • LibraryName is the library name as it appears in the browser. For a custom library, you set this value in the slblocks.m file with the Browser.Name property.

    • Sublibrary is the name of the sublibrary or, for a custom library, a Subsystem block. You can specify a block inside the subsystem in your library or in a library that you open by way of the subsystem’s OpenFcn callback. See Create a Custom Library.

    • Block is the block name.

  • 'State' is 'Disabled' or 'Hidden'.

For example, this code hides the Sources sublibrary of the Simulink library and disables the Sinks sublibrary.

cm.LibraryBrowserCustomizer.applyFilter({'Simulink/Sources','Hidden'});
cm.LibraryBrowserCustomizer.applyFilter({'Simulink/Sinks','Disabled'});

This code disables the Sqrt block in the sublibrary opened by way of the Subsystem2 block in the custom library 'My Library'.

cm.LibraryBrowserCustomizer.applyFilter(...
{'My Library/Subsystem2/Sqrt','Disabled'});

After adding or modifying the sl_customization.m file, enter sl_refresh_customization at the MATLAB command prompt to see the customizations take effect.

Expand or Collapse Library in Browser Tree

You can add a customization to expand or collapse any library in the Library Browser tree by default. For example, the Simulink library is expanded by default. You can specify to instead collapse it by default. Add code in this form to your sl_customization.m file:

cm.LibraryBrowserCustomizer.applyNodePreference(...
{'libraryName',logical});

Use true to expand the library and false to collapse it.

For example, this code collapses the Simulink library and expands the Simscape library:

function sl_customization(cm) 
  cm.LibraryBrowserCustomizer.applyNodePreference(...
{'Simulink',false,'Simscape',true}); 
end

This code collapses a custom library named 'My Library'.

function sl_customization(cm) 
     cm.LibraryBrowserCustomizer.applyNodePreference(...
{'My Library',false}); 
end

After adding or modifying the sl_customization.m file, enter sl_refresh_customizations at the MATLAB command prompt to see the customizations take effect.

Related Topics