Change "current block"/gcb/gcbh programmatically
Show older comments
Hey MATLABers,
is there any way to change the current block in Simulink, which will be returned by gcb/gcbh? I would like to start GUIs programmatically, but their code relies on gcb (works perfectly, as long as you start a GUI by double-clickling).
Unfortunately, the following code does not make a block the current block:
>> set_param(hBlock,'Selected','on');
>> isequal(hBlock,gcbh)
ans =
0
Other possibility: programmatically trigger a mouse-click on a Simulink block, but I don't know how...
Thanks very much and best regards
Thomas
1 Comment
Thomas Becker
on 15 Sep 2016
Accepted Answer
More Answers (1)
Fangjun Jiang
on 12 Aug 2016
The best way to resolve this is to use the actual block path or block handle, instead of gcb/gcbh. You could modify the function. At the beginning of the code, assign
CurrentBlock='ModelName/SubsystemName/BlockName';
CurrentBlockHandle=get_param(CurrentBlock,'Handle');
Then do a find&replace on gcb and gcbh.
According to R2015b document, there is many ways gcb/gcbh could change.
The current block is one of these:
During editing, the current block is the block most recently clicked.
During simulation of a system that contains S-Function blocks, the current block is the S-Function block currently executing its corresponding MATLAB® function.
During callbacks, the current block is the block whose callback routine is being executed.
During evaluation of the MaskInitialization string, the current block is the block whose mask is being evaluated.
Another quick and dirty way that I hesitate to suggest, is that if all those processing happen inside a function, you could create the variable gcb and gcbh to overwrite the function gcb and gcbh.
1 Comment
Thomas Becker
on 15 Sep 2016
Categories
Find more on Programmatic Model Editing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!