MATLAB: How to exclude items from the exported Simulink Web View programmatically

Simulink Report Generator

I would like to export my model to a Web View but there are certain blocks and subsystems in my model that I want to exclude from the Web View for IP protection purposes. I know you can do this from using the "Systems to Exclude" tab of the Web Export options GUI as shown in the link below:
However, I would like to do this programmatically. How can I do this?

Best Answer

In MATLAB R2017a and newer you can programmatically exclude systems from your model Web View with a custom "FilterCallback" in the slreportgen.webview.ExportOptions class. See the link below for more details. See the attached script for an example where a custom FilterCallback function removes the details of the "shift_logic" subsystem from the Web View for the 'sf_car' example model.
In MATLAB R2016b and older, the suggested workaround is to do this manually using the "Systems to Exclude" tab of the Web Export options GUI as shown in the link below: