How to add icon to sl_action_schema in sl_customization?

3 Ansichten (letzte 30 Tage)
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 16x16 and 24x24 with relative and absolute path. Tried only png so far (for example the help16x16.png file from the MATLAB installation folders).

Akzeptierte Antwort

Christian Dengler
Christian Dengler am 2 Aug. 2018
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
  2 Kommentare
Hartmut Pohlheim
Hartmut Pohlheim am 19 Jun. 2019
Hello, Christian,
Thank you very much for the detailed answer. Works great, thanks a lot!
Hartmut
Praveen Kumar
Praveen Kumar am 5 Nov. 2019
i need solution in sl_customization checked option. Kindly solve this.
if i click medium it should be checked and another options are unchecked. how can i ensure via sl customiztion code. Please tell me as soon as possible. Thanks in advance. Have a great day...
Reference.PNG

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Introduction to Installation and Licensing finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by