필터 지우기
필터 지우기

Method for determining height and width of a Simulink annotation

조회 수: 6 (최근 30일)
Douglas
Douglas 2013년 10월 28일
댓글: Douglas 2013년 10월 29일
or other text object, like a block name, block annotation ["AttributesFormatString"].
Inputs: Text & Font info (FontAngle, FontName, FontSize, FontWeight).
Outputs: height/width of bounding rectangle - in same units as the "position" parameter for a block.
Needed to allow check for overlapping text, adjusting block dimensions, etc.
Pretty clear such a function exists internal to Simulink (needed to draw text, draw borders around annotations, etc.) -- but damned if I can find it in R2013a.
  댓글 수: 1
Douglas
Douglas 2013년 10월 29일
편집: Douglas 2013년 10월 29일
OK - I found one method for an annotation or purely text string -
hdl = add_block(gcs, testString, 'Position', remotePos)
ob = get_param(hdl,'object')
bb = ob.getBounds;
wh = bb(3:4)-bb(1:2);
There's a couple wrinkles - need to strrep(...) any '/' chars in the string with '//' and any '\n' with char(10).
One problem this doesn't solve, however, is block annotations. Is there a method of getting the actual string that's displayed (after variable substitution?)
The 'AttributeFormatString" is just that, a format string. To estimate the bounding box, one needs to replace each format item %<ParamName> in the AttributesFormatString with the actual value of the parameter. Is this string available from the block via some method or parameter?
Or is it necessary for each Simulink user to write a snippet to identify instances of %<ParamName> in the AttributesFormatString and do the appropriate substitution? Tedious and introduces special cases - and, again - Simulink has already done this internally in order to display the block annotation text.

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

답변 (1개)

Zack Peters
Zack Peters 2013년 10월 29일
Hi Douglas,
In Simulink, annotations are classified by Simulink.Annotation objects. These can be programmatically located via the find_system command.
If you know any distinguishing features of the annotation that you are interested in then you can track down the object for that specific one and from there you should be able to modify the annotation object's properties using the methods demonstrated in the link above.
~Zack
  댓글 수: 1
Douglas
Douglas 2013년 10월 29일
Zack,
Using ob.getBounds solved my problem for Simulink.Annotations, as I mentioned in my comment.
What I don't have is a clean solution for BLOCK Annotations -- eg. the text for a BLOCK that is generated by the 'AttributesFormatString'
I am using the term "Block Annotation" because this is the name of the Block Properties tab where a user can define the AttributesFormatString via the GUI [vs. programmatically]

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

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by