Annotations with rich text corrupted after saving model

1 vue (au cours des 30 derniers jours)
Arjan Oskam
Arjan Oskam le 8 Juin 2022
Good day,
I made a script where I create a model programmatically, and also add an Annotation with rich text in it, containing a web link. This is working fine, the Annotation is created and the link can be clicked. However after saving the model, closing it, and reopening it, the annotation shows only the plain text with the control codes in it. Apparently the “Interpreter = ‘rich’” property is lost after saving the model.
I have attached a small script that creates a model with an annotation. Am I doing something wrong when creating the annotation in the script?
After running the script:
After saving, closing, reopening the model:
Also the properties before and after saving are different (Name, Text, and PlainText):
Before saving:
>> ah = find_system(gcs, 'FindAll', 'on', 'type', 'annotation');
>> get( ah )
Path: 'ann_test'
Name: 'This is a test with rich text <br>with a link to a website <br><br>Create annotations programmatically'
Tag: ''
Description: ''
Type: 'annotation'
Parent: 'ann_test'
Handle: 2.0011
HiliteAncestors: 'none'
RequirementInfo: ''
FontName: 'auto'
FontSize: 12
FontWeight: 'auto'
FontAngle: 'auto'
Selected: 'off'
Position: [100 100 300 158]
InternalMargins: [0 0 0 0]
IsImage: 'off'
FixedHeight: 'off'
FixedWidth: 'on'
HorizontalAlignment: 'left'
VerticalAlignment: 'top'
ForegroundColor: 'black'
BackgroundColor: 'white'
Text: 'This is a test with rich text <br>with a link to a website <br><br>Create annotations programmatically'
PlainText: 'This is a test with rich text with a link to a website Create annotations programmatically'
DropShadow: 'on'
AnnotationType: 'note_annotation'
Interpreter: 'rich'
TeXMode: 'off'
ShowInLibBrowser: 'off'
MarkupType: 'model'
ClickFcn: ''
LoadFcn: ''
DeleteFcn: ''
UseDisplayTextAsClickCallback: 'off'
UserData: []
After saving and reopening:
>> ah = find_system(gcs, 'FindAll', 'on', 'type', 'annotation');
>> get( ah )
Path: 'ann_test'
Name: '<html><body>This is a test with rich text &lt;br&gt;with a link to a website &lt;br&gt;&lt;br&gt;&lt;a href=&quot;https://www.mathworks.com/help/simulink/ug/create-an-annotation-programmatically.html&quot;&gt;Create annotations programmatically&lt;/a&gt;</body></html>'
Tag: ''
Description: ''
Type: 'annotation'
Parent: 'ann_test'
Handle: 2.0012
HiliteAncestors: 'none'
RequirementInfo: ''
FontName: 'auto'
FontSize: 12
FontWeight: 'auto'
FontAngle: 'auto'
Selected: 'off'
Position: [100 100 300 200]
InternalMargins: [0 0 0 0]
IsImage: 'off'
FixedHeight: 'off'
FixedWidth: 'on'
HorizontalAlignment: 'left'
VerticalAlignment: 'top'
ForegroundColor: 'black'
BackgroundColor: 'white'
Text: '<html><body>This is a test with rich text &lt;br&gt;with a link to a website &lt;br&gt;&lt;br&gt;&lt;a href=&quot;https://www.mathworks.com/help/simulink/ug/create-an-annotation-programmatically.html&quot;&gt;Create annotations programmatically&lt;/a&gt;</body></html>'
PlainText: 'This is a test with rich text <br>with a link to a website <br><br>Create annotations programmatically'
DropShadow: 'on'
AnnotationType: 'note_annotation'
Interpreter: 'rich'
TeXMode: 'off'
ShowInLibBrowser: 'off'
MarkupType: 'model'
ClickFcn: ''
LoadFcn: ''
DeleteFcn: ''
UseDisplayTextAsClickCallback: 'off'
UserData: []
It’s a minor issue, but annoying nonetheless. I hope you can help me out here, thanks.

Réponse acceptée

Arjan Oskam
Arjan Oskam le 9 Juin 2022
Never mind, I found the solution is to enclose the text in <html> <body> tags:
txt = ['<html><body>' ...
'This is a test with rich text <br>' ...
'with a link to a website <br><br>' ...
'<a href="https://www.mathworks.com/help/simulink/ug/create-an-annotation-programmatically.html">Create annotations programmatically</a>' ...
'</body></html>'];
Now the annotation is restored properly after saving, closing, and re-opening the model.

Plus de réponses (0)

Catégories

En savoir plus sur Subsystems dans Help Center et File Exchange

Tags

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by