{"id":2792,"date":"2011-05-20T13:37:32","date_gmt":"2011-05-20T13:37:32","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2011\/05\/20\/add-a-list-of-favorite-blocks-to-the-simulink-context-menu\/"},"modified":"2011-05-20T13:37:32","modified_gmt":"2011-05-20T13:37:32","slug":"add-a-list-of-favorite-blocks-to-the-simulink-context-menu","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2011\/05\/20\/add-a-list-of-favorite-blocks-to-the-simulink-context-menu\/","title":{"rendered":"Add a List of Favorite Blocks to the Simulink Context Menu"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction>\r\n      <p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/32620\">Greg's<\/a> Pick of the Week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/30248-add-simulink-blocks-from-a-given-model-file-with-context-menu\">Add Simulink Blocks from a given Model File with context menu<\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/101247\">Paul<\/a>.\r\n      <\/p>\r\n      <p>While newer versions of Simulink have a feature that lists the most commonly used blocks in the context menu, this File Exchange\r\n         entry allows you to explicitly define blocks that you want available from the context menu.\r\n      <\/p>\r\n      <p>This File Exchange entry also provides a good example of how to customize the Simulink environment.<\/p>\r\n   <\/introduction>\r\n   <h3>Contents<\/h3>\r\n   <div>\r\n      <ul>\r\n         <li><a href=\"#1\">Add This Custom Menu to Your Simulink Installation<\/a><\/li>\r\n         <li><a href=\"#2\">How Is This Different Than \"Most Frequently Used Blocks\"?<\/a><\/li>\r\n         <li><a href=\"#3\">How Does the Custom Menu Work?<\/a><\/li>\r\n      <\/ul>\r\n   <\/div>\r\n   <h3>Add This Custom Menu to Your Simulink Installation<a name=\"1\"><\/a><\/h3>\r\n   <p>Once you have downloaded this File Exchange entry and unzip it, make sure that you:<\/p>\r\n   <li>Ensure the directory where you unzipped the file is on the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2011a\/techdoc\/\/matlab_env\/br7ppws-1.html#bsdv_lr\">MATLAB Path<\/a>.\r\n   <\/li>\r\n   <li>Enter the following at the MATLAB Command Prompt<\/li><pre>&gt;&gt; sl_refresh_customizations<\/pre><p>Now when you right-click on the Simulink canvas, there is a list of the blocks found in the custom_context_menu_blocks.mdl\r\n      file.\r\n   <\/p>\r\n   <p><a href='https:\/\/blogs.mathworks.com\/pick\/..\/images\/pick\/rightclicklibrary_screenshot.jpg' title='rightclicklibrary_screenshot.jpg'><img src='https:\/\/blogs.mathworks.com\/pick\/..\/images\/pick\/rightclicklibrary_screenshot.jpg' alt='rightclicklibrary_screenshot.jpg' \/><\/a><\/p>\r\n   <h3>How Is This Different Than \"Most Frequently Used Blocks\"?<a name=\"2\"><\/a><\/h3>\r\n   <p>Many of you may note that in more recent versions of Simulink, there is a list of the most frequently used blocks available\r\n      in the context menu for the Simulink canvas.\r\n   <\/p>\r\n   <p><a href='https:\/\/blogs.mathworks.com\/pick\/..\/images\/pick\/frequently_used_blocks.png' title='frequently_used_blocks.png'><img src='https:\/\/blogs.mathworks.com\/pick\/..\/images\/pick\/frequently_used_blocks.png' alt='frequently_used_blocks.png' \/><\/a><\/p>\r\n   <p>The blocks listed here change depending which library blocks are used most often. The list that is created using Paul's method\r\n      is static, and does not change based on usage. In addition the names that appear in Paul's list don't use the full library\r\n      path name for the block.\r\n   <\/p>\r\n   <h3>How Does the Custom Menu Work?<a name=\"3\"><\/a><\/h3>\r\n   <p>Paul takes advantage of the Simulink customization feature \"sl_customization.m\" files.<\/p>\r\n   <p>The SL_CUSTOMIZATION file contains a definition of the customization, as well as the callback functions that might be executed\r\n      as part of the customization.\r\n   <\/p>\r\n   <p>These files can be used to:<\/p>\r\n   <div>\r\n      <ul>\r\n         <li>Customize Menus<\/li>\r\n         <li>Customize views of the Simulink library browser<\/li>\r\n         <li>Disable buttons and options in the model configuration parameters<\/li>\r\n         <li>Hook into the C-code generation process in <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2011a\/toolbox\/rtw\/gs\/f19481.html\">Simulink Coder<\/a><\/li>\r\n         <li>Create custom checks for the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2011a\/toolbox\/simulink\/ug\/f4-141979.html\">Simulink Model Advisor<\/a><\/li>\r\n      <\/ul>\r\n   <\/div>\r\n   <p>The sl_refresh_customizations command is used to register the SL_CUSTOMIZATION files with Simulink.<\/p>\r\n   <p>For more information on customizing Simulink and the SL_CUSTOMIZATION functions, check out <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2011a\/toolbox\/simulink\/ug\/bqt2_on.html\">Customizing the Simulink User Interface<\/a><\/p>\r\n   <p><b>Comments<\/b><\/p>\r\n   <p>If you would like to leave any comments regarding this post, please click <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=2792#respond\">here<\/a>.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_e78a9c803e7049b096fc476c41fb608f() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='e78a9c803e7049b096fc476c41fb608f ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' e78a9c803e7049b096fc476c41fb608f';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Greg Wolff';\r\n        copyright = 'Copyright 2011 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_e78a9c803e7049b096fc476c41fb608f()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; 7.12<br><\/p>\r\n<\/div>\r\n<!--\r\ne78a9c803e7049b096fc476c41fb608f ##### SOURCE BEGIN #####\r\n%% Add a List of Favorite Blocks to the Simulink Context Menu\r\n%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/32620 Greg's>\r\n% Pick of the Week is \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/30248-add-simulink-blocks-from-a-given-model-file-with-context-menu Add Simulink Blocks from a given Model File with context menu>\r\n% by <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/101247 Paul>.\r\n% \r\n% While newer versions of Simulink have a feature that lists the most\r\n% commonly used blocks in the context menu, this File Exchange entry allows\r\n% you to explicitly define blocks that you want available from the context\r\n% menu.\r\n% \r\n% \r\n% This File Exchange entry also provides a good example of how to customize\r\n% the Simulink environment.\r\n\r\n%% Add This Custom Menu to Your Simulink Installation\r\n% Once you have downloaded this File Exchange entry and unzip it, make sure\r\n% that you:\r\n%\r\n% # Ensure the directory where you unzipped the file is on the <https:\/\/www.mathworks.com\/help\/releases\/R2011a\/techdoc\/\/matlab_env\/br7ppws-1.html#bsdv_lr MATLAB Path>.\r\n% # Enter the following at the MATLAB Command Prompt\r\n%\r\n%  >> sl_refresh_customizations\r\n% \r\n% Now when you right-click on the Simulink canvas, there is a list of\r\n% the blocks found in the custom_context_menu_blocks.mdl file.\r\n%\r\n% <<rightclicklibrary_screenshot.jpg>>\r\n% \r\n\r\n%% How Is This Different Than \"Most Frequently Used Blocks\"?\r\n%\r\n% Many of you may note that in more recent versions of Simulink, there is a\r\n% list of the most frequently used blocks available in the context menu for\r\n% the Simulink canvas.\r\n%\r\n% <<frequently_used_blocks.png>>\r\n%\r\n% The blocks listed here change depending which library blocks are used most often.\r\n% The list that is created using Paul's method is static, and does not change based on usage.\r\n% In addition the names that appear in Paul's list don't use the full library path\r\n% name for the block.\r\n\r\n\r\n\r\n%% How Does the Custom Menu Work?\r\n% Paul takes advantage of the Simulink customization feature\r\n% \"sl_customization.m\" files.\r\n%\r\n% The SL_CUSTOMIZATION file contains a definition of the customization, as\r\n% well as the callback functions that might be executed as part of the\r\n% customization.\r\n%\r\n% These files can be used to:\r\n%\r\n% * Customize Menus\r\n% * Customize views of the Simulink library browser\r\n% * Disable buttons and options in the model configuration parameters\r\n% * Hook into the C-code generation process in\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2011a\/toolbox\/rtw\/gs\/f19481.html Simulink Coder>\r\n% * Create custom checks for the\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2011a\/toolbox\/simulink\/ug\/f4-141979.html Simulink Model Advisor>\r\n%\r\n%\r\n% The sl_refresh_customizations command is used to register the\r\n% SL_CUSTOMIZATION files with Simulink.\r\n%\r\n% For more information on customizing Simulink and the SL_CUSTOMIZATION functions, check out\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2011a\/toolbox\/simulink\/ug\/bqt2_on.html\r\n% Customizing the Simulink User Interface>\r\n%\r\n\r\n%%\r\n% *Comments*\r\n%\r\n% If you would like to leave any comments regarding this post, please click \r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=2792#respond here>. \r\n##### SOURCE END ##### e78a9c803e7049b096fc476c41fb608f\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   \r\n      Greg's Pick of the Week is Add Simulink Blocks from a given Model File with context menu by Paul.\r\n      \r\n      While newer versions of Simulink have a feature that lists... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2011\/05\/20\/add-a-list-of-favorite-blocks-to-the-simulink-context-menu\/\">read more >><\/a><\/p>","protected":false},"author":44,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2792"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/44"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=2792"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2792\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2792"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2792"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2792"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}