How to get the new value of a changed mask parameter in the dialog callback?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
Hello, I am using Matlab R2011a. I have created a subsystem and masked it. There is a popup parameter in my mask and I have added a dialog callback to handle some things when the user changes the popup selection. At the moment, it seems as if in the dialog callback, when getting the value of the popup parameter with get_param(gcb,<parametername>), the old value is returned. Is there a way to get the current value of it?
Thank you,
Christian
Accepted Answer
Kaustubha Govind
on 29 May 2013
I think you need to just use the 'parametername' directly since it exists as a variable in the Mask workspace. Does that work?
8 Comments
Christian
on 6 Jun 2013
I am not sure what I am doing wrong, but I can't see my mask variable in the workspace. I simply tried disp(<parametername>) in the Dialog callback edit field, but I got an error message that the variable is unknown. Is there any way to hide variables from the mask workspace? Since there are a number of scripts involved in mask initialization and block callbacks and not all of them are my code, I am not sure if for some reason, the variable is hidden or access protected. If not, is there any way to force a block to update it's internal states of the mask parameters, so that get_param would return the current value?
Thanks,
Christian
Kaustubha Govind
on 6 Jun 2013
Are you using the same parametername that you use for your call to get_param? Is this same parametername in the list of Mask Variables, or is it created locally during Mask Initialization?
Christian
on 6 Jun 2013
Yes, it is definitely the same name as used in get_param and as defined in the list of mask variables. When I use a 'keyboard;' command in the Dialog callback, to stop execution at that point, using 'who' in the command window does not show any of my mask variables. Should the parameters from the mask workspace be visible using 'who' at that point?
Christian
on 13 Jun 2013
I am still struggeling with this problem and was not able to find a way to get the current value of the mask parameter. Is there any other idea what could be wrong?
Kaustubha Govind
on 13 Jun 2013
Christian: I think I was wrong - the mask variables are available in the Mask Initialization function, but that doesn't appear to be true for the dialog callbacks. I just tried with a simple experiment, and get_param does appear to be giving me the newly entered value for the parameter, so I'm not sure why you're seeing the issue to begin with. Perhaps you could trim down your model and send it to MathWorks Support?
I was able to create a very basic model which behaves as described. While reducing the block complexity, I detected that the block is a bit special and maybe this causes the problem: The block dialog is not opened with the usual double-click, but instead, the OpenCallback of the block is used:
bl_o=get_param(gcb,'object');
dlg=DAStudio.Dialog(bl_o.getDialogSource);
dlg.show;
This is because in the original block, a lot of other stuff is done in the OpenCallback and therefore, the mask dialog needs to be opened like this.
Now, I have this mask parameter 'param1' (popup) and the following DialogCallback:
value = get_param(gcb,'param1');
disp(value);
When I open the mask dialog and change the value, it always shows the old value. Furthermore, when I click OK to close the dialog and open it again, the parameter has the old value again.
Is this intended behaviour?
I will also send this model to the Mathworks Support.
Thank you.
Kaustubha Govind
on 14 Jun 2013
Christian: It looks like the Open callback is creating a new dialog (using DAStudio.Dialog). You can see this by running the same code from the command window on let's say, a Constant block in a model. You'll see that dlg.show opens a dialog, but when you double-click on the Constant block, there is a second dialog window opened. So, essentially, it is physically separate from the Mask dialog, which is why the callback is not getting the right values. I'm not sure how this new dialog interacts with the Mask dialog and invokes the right callback though. I think this problem is beyond my expertise, so I would recommend waiting to see what Tech Support recommends.
Christian
on 14 Jun 2013
Thank you for mentioning that the Open Callbacks opens another instance of the mask dialog. This is correct and it brought me to a solution finally:
t = DAStudio.ToolRoot;
dv = t.getOpenDialogs;
value = dv(1).getWidgetValue('Parameter1')
This will give me the current value of param1. The argument passed to getWidgetValue is NOT the name of the mask variable, but the prompt of it, as defined in the mask. Thanks a lot for your support.
More Answers (0)
Categories
Find more on Author Block Masks in Help Center and File Exchange
Products
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)