This can be performed by finding the handles to the blocks which are in a particular network (i.e. SimPowerSystems), and using the "hilite_system" function to highlight blocks or the "set" function with the "ForegroundColor" field to change the foreground color.
The following code shows how this would be performed. This example looks for blocks in the Simscape Library, and highlights them. If blocks from the SimPowerSystems library needed to be highlighted, the "ReferenceBlock" field would need to be changed to powerlib.
The ReferenceBlock fields for the different networks are "fl_lib" for Simscape, "sdl_lib" for SimDriveline, "elec_lib" for SimElectronics, "sh_lib" for SimHydraulics, "sm_lib" for SimMechanics, "powerlib" for SimPowerSystems.
blocks = find_system(gcs,'Type','Block');
handles = zeros(1,length(blocks));
for i = 1:length(blocks)
handles(i) = get_param(blocks{i},'Handle');
if strfind(get(handles(i),'ReferenceBlock'),'fl_lib')
hilite_system(blocks{i})
else
end
end
A demo model "highlight_model.slx" and the corresponding script "highlight_network.m" have been attached. To run the demo, open the model and run the script. The Simscape blocks should be highlighted. If you would like the foreground color to change, uncomment the "set" function lines corresponding to the foreground color.
Best Answer