Change "current block"/gcb/gcbh programmatically
Mostrar comentarios más antiguos
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 comentario
Thomas Becker
el 15 de Sept. de 2016
Respuesta aceptada
Más respuestas (1)
Fangjun Jiang
el 12 de Ag. de 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 comentario
Thomas Becker
el 15 de Sept. de 2016
Categorías
Más información sobre Programmatic Model Editing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!