MATLAB: How to find the top level of the entire system from within an active model reference

findmodel referencesimulink

My MEX functions look upwards in the subsystem heirarchy to get some information from top-level configuration blocks, which specify system wide parameters for my system. Normally I would find these with find_system(bdroot(gcb), …).
But supposing I want to use model referencing. Is there any way a block in a referenced model can, during initialization of a system referencing it, find the top level of the referencing system? bdroot(gcb) will only get me to the top of the referenced model – not the active referencing model.

Best Answer

Hi Mark,
the only way I could think of:
myModelName = get_param(bdroot(gcb), 'Name');
% find all model reference blocks that contain "me"
blocks = find_system('BlockType', 'ModelReference', ...
'ModelName', myModelName);
models = bdroot(blocks);
Does this help?
Titus