I am writing a Model Advisor check right now and I need to know the size of a subcharted Stateflow State or Box. But the "Stateflow.State" and "Stateflow.Box" objects only have a "Position" attribute, which gives their position inside their parent elements. I need to know the size of the subchart itself (where their contents reside). How can I get this size?
2 Answers
The "Position" attribute is the absolute position of "Stateflow.State" inside the Chart.Here is an example:
___________________
|AA |
|___________ |
||BB | |
||_________| |
-------------------
AA = r.find('-isa', 'Stateflow.State', 'Name', 'AA').Position
AA = 330.0924 542.7458 157.4576 94.6164
BB = r.find('-isa', 'Stateflow.State', 'Name', 'BB').Position
BB = 334.5304 571.1490 115.7404 62.6628

- 378
- 1
- 3
- 7
-
You're right. But what I need is the size of AA, if it is subcharted. Then BB's position is the absolute position inside the Stateflow.State AA and not the chart. And I then need the size (not necessarily the position) of AA as you have drawn it. – walderich Apr 04 '15 at 08:48
-
The attribute "Position" is consist of the coordinate of the upper - left corner , the width and height of the state. – lililqth Apr 05 '15 at 10:02
I finally asked the MathWorks support for a solution and got this answer:
[...] there is currently no API functionality to retrieve the size of the subchart in the subchart subviewer. Unfortunately there are no workarounds to access this information currently.
Update: I recently learned about the undocumented sf
API. It is possible to get information about the subchart with it. Therefore you need to get the ID of the State whos dimensions are needed. Here is an example:
r = sfroot;
s = r.find('-isa', 'Stateflow.State', '-and', 'IsSubchart', 1);
sf('get', s(1).id, '.subviewS.pos')
This does the following:
- Store the
Simulink.Root
object inr
. - Find all subcharted States and store them in
s
. You might need to refine the search to detect the exact State you need. - Use the
sf
API to retrieve the position.pos
of the first Subchart, which is represented by.subviewS
There is plenty of information about each of the Stateflow objects. To investigate further, you just need to find the appropriate object (using r.find()
) and use sf('get', <object>.id)
. This lists all available information about the Stateflow object <object>
.

- 500
- 1
- 9
- 24