MATLAB: How to send custom input arguments from ‘rtwbuild’ function to a hook file (STF_make_rtw_hook)

hook-filesimulink coder

I have created a custom hook file (STF_make_rtw_hook) that I only want to run if called from a script.
I want to pass a custom input argument in 'rtwbuild' that when set to true would run the hook file.
For example, if I have a custom hook file like the one below:
>> if UseMyFileDiffTool
>> runDiffTool()
>> end
Then, I would like to call 'rtwbuild' with a custom input argument like this:
>> rtwbuild(model,'UseMyFileDiffTool',true)
Having that input argument set to true, it would run the hook file from above. How can I implement this?

Best Answer

The ability to use custom input arguments in the 'rtwbuild' function is not available in R2019b. However, as a workaround you can use an environment variable or another persistent state that can control the behaviour inside the STF_make_rtw_hook file. For example:
>> setenv('UseMyFileDiffTool','1');
Then, in your STF_make_rtw_hook file, you can query the environment variable using the 'getenv' function to check if it's set to '1' or '0' and therefore execute your hook file accordingly.
Another possible workaround would be to add a custom option to the target called 'UseMyFileDiffTool' that would be settable on the model. You can refer to the following documentation page regarding this workflow:
See section on 'Define and Display Custom Target Options':
You can then set this option on your script or Command Window programmatically before calling the 'rtwbuild' function.