I have a parent model "topLevelModel" and a referenced model "gainRefModel." The referenced model's PreLoadFcn and InitFcn callbacks contain the line of code
Param.gainRefModel.Gain = 5.0
for setting the gain value of a Gain block. I have also created a build function for changing the Param structure to a Simulink.Parameter object before issuing the rtwbuild command. As the model compiles, I receive the error
Error evaluating 'InitFcn' callback of block_diagram 'gainRefModel'.
I understand this arises because the Init callback is executed as the model compiles, and there is an assignment error because there is no field called gainRefModel for class Simulink.Parameter. I cannot, however, remove the contents of the Init callback for simulation purposes. Is there is a way to tell Simulink to ignore the InitFcn callback only during builds?
Best Answer