MATLAB: How to add icon to sl_action_schema in sl_customization

iconsimulinksl_action_schemasl_customization

Hello Mathworks Team, how can I add an icon to an sl_action_schema in sl_customization? This is what I tried so far:
function schema = getItemMyEntry(callbackInfo)
schema = sl_action_schema;
schema.label = 'MyEntry';
schema.icon = 'MyIcon.png';
schema.callback = @myEntryCallback;
end
The entry appears in the Simulink menu, but without an icon. I tried icons of size 16×16 and 24×24 with relative and absolute path. Tried only png so far (for example the help16x16.png file from the MATLAB installation folders).

Best Answer

Hello Hartmut,
to use icons on sl_*_schema is not a documented feature, nevertheless I found out howto do it. There are two steps you have to take:
  1. Getting your icons into the IconManager of DAStudio
  2. Using these icons in schemas
1) There two possible ways to get your icons into IconManager.
1a) Using dig.xml
Create a file called "dig.xml", MATLAB path must point to the location this file. When MATLAB starts, the defined icons will be installed.
Example content:
<dig>
<icon id="MyToolbox:Inport" size="16">/toolbox/simulink/sysarch/sysarch/resources/InputPort_16.png</icon>
<icon id="MyToolbox:Outport" size="16">/toolbox/simulink/sysarch/sysarch/resources/OutputPort_16.png</icon>
<icon id="MyToolbox:Const" size="16">/toolbox/shared/dastudio/resources/SimulinkNumericType.png</icon>
</dig>
I only managed to use icons located below $MATLABROOT (e.g. "C:\Program Files\MATLAB\R2016B"). The icon paths in dig.xml are relative to $MATLABROOT. So this solution is not optimal, if you have your own icons and your toolbox is not located below $MATLABROOT. So check out option 1b.
1b) Using DAStudio.IconManager
Create a function "InstallIcons" within your "sl_customization.m" file. Call InstallIcons() at the beginning of sl_customization.
function InstallIcons()
% (00) Settings
namespace = 'MyToolbox'; % Namespace for icons
% (01) Get path to me (=sl_custumization.m)
mFile = mfilename('fullpath');
% (02) Get path of me
[mPath, ~] = fileparts(mFile);
% (03) Iconmanager object
im = DAStudio.IconManager;
%---------------------------------------

% (04) Add the icons to iconmanager
%---------------------------------------
im.addFileToIcon( [namespace ':SelectAll'] , fullfile(mPath, 'resources', 'SelAll1.png') );
im.addFileToIcon( [namespace ':MoveBack'] , fullfile(mPath, 'resources', 'back1.png') );
end
I put my icons in a subdirectory "resources" below my toolbox directory (where "sl_customization.m" is located). Have a look at the file "$MATLABROOT\toolbox\shared\dastudio\+DAStudio\Actions.m" within your MATLAB installation for more hints.
2.) Using the icons in schemas
function schema = getItemMyEntry(callbackInfo)
schema = sl_action_schema;
schema.label = 'MyEntry';
schema.callback = @myEntryCallback;
schema.tag = 'MyToolbox:MoveBack';
schema.icon = schema.tag;
end
Regards from Stuttgart
Christian