MATLAB: How to generate code only for the referenced model when I only want to work with the top model

simulink

I want to generate codes for the referenced model but I do not want to click 'Build' on the referenced model as I find it more convenient to only work with the top model of my system. Is there a way that I can generate codes for the referenced model when I only have the top model in front of me?

Best Answer

There is no direct way of doing it in the Configuration Parameters settings. However, there is a workaround and please refer to the model in the attachment. Here is a few notes for the attached model.
1. I have added a Model Info Block and masked it as 'Build refModel'. I have also edited the OpenFcn callback functions of the block (right click on the block -> Properties ->  Callbacks -> OpenFcn).
2. The script in OpenFcn is to get the Configuration Parameters set from the refModel, set it to generate code only and build the referenced model. 
3. You can double click on the 'Build refModel' block to modify the Configuration Parameters of refModel and generate code for the refModel only. 
Related Question