Effacer les filtres
Effacer les filtres

Method for determining height and width of a Simulink annotation

6 vues (au cours des 30 derniers jours)
Douglas
Douglas le 28 Oct 2013
Commenté : Douglas le 29 Oct 2013
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 commentaire
Douglas
Douglas le 29 Oct 2013
Modifié(e) : Douglas le 29 Oct 2013
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.

Connectez-vous pour commenter.

Réponses (1)

Zack Peters
Zack Peters le 29 Oct 2013
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 commentaire
Douglas
Douglas le 29 Oct 2013
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]

Connectez-vous pour commenter.

Catégories

En savoir plus sur Programmatic Model Editing dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by