How do you control the format of a multi-line note?

Using code like

Annot.GetTextFormat(0)

and

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.

You could try treating the multi-line note as a paragraph.

Get and Set Paragraph Properties Example (VBA)

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-api/document/notes/get-note-format-text/

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?p=36380&hilit=notebrowser#p36380
image.png
image.png

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.

Thank you, Josh. That’s very helpful and that tool is amazing.