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

Programming and macros
User avatar
loeb
Posts: 66
Joined: Sun Jan 16, 2022 5:55 pm
Answers: 1
x 38
x 10

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

Unread post by loeb »

Using code like

Code: Select all

Annot.GetTextFormat(0)
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.
User avatar
SPerman
Posts: 2035
Joined: Wed Mar 17, 2021 4:24 pm
Answers: 14
x 2200
x 1859
Contact:

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

Unread post by SPerman »

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

Get and Set Paragraph Properties Example (VBA)
-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
User avatar
loeb
Posts: 66
Joined: Sun Jan 16, 2022 5:55 pm
Answers: 1
x 38
x 10

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

Unread post by loeb »

SPerman wrote: Tue Oct 29, 2024 7:41 am 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-ap ... rmat-text/
User avatar
josh
Posts: 292
Joined: Thu Mar 11, 2021 1:05 pm
Answers: 15
x 22
x 499

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

Unread post 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
image.png
image.png
retonny77
Posts: 19
Joined: Fri Sep 20, 2024 5:34 am
Answers: 0
x 1
x 6

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

Unread post by retonny77 »

for i in range(numberOfLines):
lineFormat = Annot.GetTextFormat(i)
# Apply any changes you need here
Annot.ISetTextFormat(i, True, newFormat)
User avatar
josh
Posts: 292
Joined: Thu Mar 11, 2021 1:05 pm
Answers: 15
x 22
x 499

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

Unread post 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.
Post Reply