Change "current block"/gcb/gcbh programmatically
显示 更早的评论
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 个)
Fangjun Jiang
2016-8-12
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Programmatic Model Editing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!