Page 1 of 1

Macro to remove some applied formatting

Posted: 2020-08-26 06:20:50
by vwnisus
I download a series of court judgements each which contain some applied formatting.

I know it is possible to remove all of it, and also individual elements of the applied formatting.

What I would like to do is to create a macro which removes only some individual elements and one style.

For example in the following:
Screenshot 2020-08-26 at 14.55.16.jpg
Screenshot 2020-08-26 at 14.55.16.jpg (86.98 KiB) Viewed 1424 times
after selecting all, I would like to remove the Text Color, Underline, Paragraph Spacing Before formatting and the Style: Hyperlink

(Some of the applied formatting varies from judgement to judgement, for example the Text Color is red or blue)

Is this possible?

Re: Macro to remove some applied formatting

Posted: 2020-08-26 07:58:19
by phspaelti
Of course you can do this, but you may need to be a bit careful.
Generally Nisus has commands to change formatting like:

Code: Select all

Set Bold isBold
as it's described in the reference. So if you have everything selected and use

Code: Select all

Set Bold @false
Then all bold is removed from your document. Interestingly enough this will even apply to the Bold that is applied through styles. It seems Nisus adds an "Unbold" attribute to those sections.

In the same way you should be able to use

Code: Select all

Set Underline 0
Where the "0" stands for no underline. If the underline was applied directly this will remove it. If the underline was applied with a style it will 'cover it' with a 'no underline' attribute.

Then you say you want to "remove the text color".Of course there always has to be some text color. I guess most people consider "black" the default. The command Set Text Color requires a color argument. I can't see a way to say "none".

Code: Select all

$black = Color.black
Set Text Color $black
Again if the color is applied via a style this will 'hide' the color by applying black over it.

Finally removing character styles: First select all in the style and the use "Remove Character Styles". For example you can select all in the style using Find. In that case it's a good idea to use a test to make sure you only remove the style in case some was found.

Code: Select all

if Find All $doc.styleWithName 'Hyperlink'
Remove Character Styles
end
[NB: I'm assuming you have set $doc to the the current document.]

Finally for the paragraph spacing you will have to know more specifically how you want to change it. There are command to set the spacing before and after, but the line height will have to be set using the menu formatting.

Finally remember that you can also reapply paragraph styles in order to enforce the default formatting as another way to clean up applied attributes.

Re: Macro to remove some applied formatting

Posted: 2020-09-02 11:05:35
by martin
phspaelti wrote:
2020-08-26 07:58:19
Then you say you want to "remove the text color".Of course there always has to be some text color. I guess most people consider "black" the default. The command Set Text Color requires a color argument. I can't see a way to say "none".
Instead of using these "Set" commands, it's probably better to work via menu commands like:

Code: Select all

Remove Text Color Formatting
Remove Underline Formatting
That won't apply a value (eg: black coloring) that overrides styles. It will only remove preexisting formatting. I think the only problem is that there's no such command for removing paragraph spacing like vwnisus wants. There's only "Remove Paragraph Formatting", which removes all paragraph formatting at once.

However, the original goal doesn't require a macro. The Formatting Examiner palette will let you pick and choose which applied formatting to remove:

1. Select all the text in your document.
2. Click the Formatting Examiner palette's listing to select a single formatting attribute (eg: Underline).
3. Hold down the Command key and click other listed formatting attributes to add them to the selection.
4. Once you've selected all the desired formatting, click the gear icon button to show the popup menu.
5. Choose the command "Remove Selected Formatting" from the popup menu.

examine.png
examine.png (213.24 KiB) Viewed 1361 times