MATLAB Answers

0

How can I get the figure handle of a Scope window programmatically, given only the Scope block's full path name?

Asked by creepydog on 26 Jun 2017
Latest activity Commented on by creepydog on 30 Jun 2017
I've got the full path name of a Scope block as it is returned by find_system(...), e.g. 'myModel/Scope1'.
In order to manipulate the corresponding Scope window using set(...), I need the handle of that window. Is there some way to call get_param('myModel/Scope1', unknownparameternamehere) to get that window handle?
What I already tried (but do not consider a solution):
(1) A workaround I'm currently using is to call set_param('myModel/Scope1','Open','On'), which sometimes makes that window the current figure, so I can use "gcf" afterwards to get the handle. But that doesn't work safely and also has unwanted side-effects.
(2) Using findobj(0,'type','figure','tag','SIMULINK_SIMSCOPE_FIGURE') to get an array of all Scope window handles doesn't help because afterwards I can't identify the Scope window in that array by its 'Name' field only: There might be 'myModel/Scope1' and 'myModel/sub/Scope1' or 'anotherModel/Scope1', so 'Name' is not unique.

  0 Comments

Sign in to comment.

1 Answer

Answer by Dhruvesh Patel on 29 Jun 2017
 Accepted Answer

There does not seem to be a documented way of getting handle to the scope window from the full-name of the scoped block.
However, as I understand, you wish to manipulate he display properties of the scope window using the handle. This can be done by obtaining 'ScopeConfiguration' object of the scope block. You can refer the following documentation pages which explain this workflow.

  3 Comments

Then perhaps someone should document it ...
Now I tried the ScopeConfiguration object (which I didn't know before). It allows me to get/set the "Position" of the Scope window, but not its "OuterPosition", which is possible using set(handle,...).
Still this helped me a lot, thanks!
I found a roundabout way of getting the handle to the scope window.
Assuming that the scope block is named 'Scope 1' in the model named 'testModel', the following sequence of commands should work.
>> open_system('testModel/Scope 1'); % opens the scope window so that it can be grabbed
>> scopeWindowH=findall(0,'Type','figure','Name','Scope 1'); % fetch the handle
See my original question, part "what I already tried", #2: 'Scope 1' might not be unique. So findall/findobj returns more than one handle and I can't find out which one's the right one.

Sign in to comment.