How can I programmitcally "click" on a block mask action button?

조회 수: 17 (최근 30일)
jason
jason 2016년 2월 10일
답변: TAB 2018년 5월 30일
I have a Simulink block which is masked. The mask contains an action button which will modify the block contents when "clicked". I need to be able to script the clicking of the button for all instances of the block. Since this block will be linked to a library the modification has to occur with in the Mask's workspace.
I've looked at the Simulink.Mask and DialogControl objects, but there is no method to envoke the button's callback, only 'get' the callback code as a string.
Is what I'm trying to do possible, and if so how?
>> errMask = Simulink.Mask.get(gcb)
errMask =
Mask with properties:
Type: 'Set_Error'
Description: '<p><font size=+3 color="#990000">Set Error</font></p>
<p></p>
<p>This block sets the system error status for the error specifi...'
Help: 'web('sfun_Set_Error_help.html', '-helpbrowser');'
Initialization: ''
SelfModifiable: 'on'
Display: 'disp(['Set Error' char(10) char(10) err_id]);'
IconFrame: 'on'
IconOpaque: 'on'
RunInitForIconRedraw: 'off'
IconRotate: 'none'
PortRotate: 'default'
IconUnits: 'autoscale'
Parameters: [1x1 Simulink.MaskParameter]
BaseMask: []
>> errBtn = errMask.getDialogControl('update_btn')
errBtn =
Button with properties:
Name: 'update_btn'
Prompt: 'Update'
Callback: 'set_error_data_stores(gcb);
disp('hello');'
FilePath: ''
Row: 'current'
Enabled: 'on'
Visible: 'on'
>> errBtn.Callback
ans =
set_error_data_stores(gcb); disp('hello');
  댓글 수: 1
Nirav Ambaliya
Nirav Ambaliya 2018년 5월 29일
Hi Jason,
Were you able to solve the problem? I am also trying to do the same thing.
Thanks, Nirav

댓글을 달려면 로그인하십시오.

답변 (2개)

Arnab Sen
Arnab Sen 2016년 2월 22일
Hi Jason, I understand that you would like to execute the callback programmatically.
You can use the 'evalin' function to achieve this goal as follows:
>>evalin(workspace,errBtn.Callback)
For more details refer to the following link:
  댓글 수: 1
jason
jason 2016년 2월 22일
Doesn't evalin only use either the 'base' or 'function' workspace? What if I need it to run in the mask's workspace?

댓글을 달려면 로그인하십시오.


TAB
TAB 2018년 5월 30일
In my understanding, Dialog Control callback is not executed in Mask workspace.
It is executed in Base workspace. Even though it is not documented explicitly, you can easily check this yourself:
  • Create a simple mask with a button and few mask parameters.
  • Now try to access a mask parameter in button callback. Eg. fprintf('Mask Param Val = %f', MyMaskParam); When you press the button you will get error.
  • Now try opposite. Print base workspace variable and it will work.
So in your case, you can call set_error_data_stores(gcb) from any in script/function to emulate the button press.

카테고리

Help CenterFile Exchange에서 Author Block Masks에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by