Thursday, November 12, 2020

[Script] Change/reset the foreground color of a block diagram/specific blocks in a block diagram

 There are specific situations where you may want to change the foreground (or even background) of blocks within a Simulink model. In some cases, you might want to revert to a stock color scheme if you've been too... creative with the colors of your diagram (or someone else who had previously worked on the same model has opted for a very colorful model). In other cases, someone might have wanted to highlight changes in a model, but this is no longer relevant since you will now implement your own. Therefore, you will have to revert to a black foreground for all blocks.

Doing this manually would be a tedious job, whereas with a script, it would be almost instantaneous. 

Let's consider the following model, where I've set the foreground color of two blocks to green.

Here's a script to revert all block foreground colors to black.


This is the end result.


Now, let's consider that you wanted to change the foreground color of all blocks of a specific type (let's say, our constant blocks). Here's a variation of the above script that will help you do that.



And here's newly highlighted model.


We can further enhance the functionality, the possibilities are endless. For example, we could create a comparison script between two models, highlighting the added or removed blocks. But that one is for another day.

No comments:

Post a Comment