Page 1 of 1
How do you control the format of a multi-line note?
Posted: Mon Oct 28, 2024 10:54 pm
by loeb
Using code like
and
Code: Select all
Annot.ISetTextFormat(i, True, swTextFormat)
I have been able to control the format of simple note annotations.
How does one control the format of multi-line notes? GetTextFormat and SetTextFormat only seem to look at the first line of the note.
Re: How do you control the format of a multi-line note?
Posted: Tue Oct 29, 2024 7:41 am
by SPerman
You could try treating the multi-line note as a paragraph.
Get and Set Paragraph Properties Example (VBA)
Re: How do you control the format of a multi-line note?
Posted: Tue Oct 29, 2024 10:49 am
by loeb
Thanks, SPerman. I didn't think about paragraphs. It's a bit unclear to me where the separation between 'notes' and 'paragraphs' is.
This is new territory for me. I'm going to share this code example here for future reference:
https://www.codestack.net/solidworks-ap ... rmat-text/
Re: How do you control the format of a multi-line note?
Posted: Wed Oct 30, 2024 8:40 am
by josh
Controlling formatting for individual portions of a note is done using SWML. Editing the note formatting using the UI or API calls are really just a way to read and write this SWML. You can use my NoteBrowser macro to read and edit the content of notes and see what the SWML is for certain formats, and you can directly edit or even type this SWML into a note to format it however you want.
This SWML actually works almost anywhere that you can have text, even if you can't use the UI to edit it.
https://www.cadforum.net/viewtopic.php? ... ser#p36380
Re: How do you control the format of a multi-line note?
Posted: Thu Oct 31, 2024 10:52 am
by retonny77
for i in range(numberOfLines):
lineFormat = Annot.GetTextFormat(i)
# Apply any changes you need here
Annot.ISetTextFormat(i, True, newFormat)
Re: How do you control the format of a multi-line note?
Posted: Thu Oct 31, 2024 12:11 pm
by josh
retonny77 wrote: ↑Thu Oct 31, 2024 10:52 am
for i in range(numberOfLines):
lineFormat = Annot.GetTextFormat(i)
# Apply any changes you need here
Annot.ISetTextFormat(i, True, newFormat)
The argument for [Get/Set]TextFormat does not refer to the line. It refers to the
piece of text. A multi-line note still only has one
piece of text. From the Help for GetTextFormatCount:
This value is not necessarily the same as the number of text objects within a symbol. For example, there are multiple text objects in a geometric tolerance symbol, but they all share the same text format so SOLIDWORKS returns 1.
In fact, for all of the annotations except blocks (and compound notes in documents created in SOLIDWORKS 2015 and earlier),
this method should return 1. For blocks and compound notes, each piece of text within the symbol has its own text format, so the return value should match the number of TextFormat objects.