Removing (some) character attributes . . .

Get help using and writing Nisus Writer Pro macros.
Post Reply
goldste4
Posts: 98
Joined: 2010-02-22 15:06:48

Removing (some) character attributes . . .

Post by goldste4 »

Hello All,

I have the following very simple macro which I use to get rid of italics and bold, etc. on the word at the insertion point (it then moves the insertion point to the next word):

Code: Select all

Menu ‘:Edit:Select:Select Word’
Menu ‘:Format:Character Style:Character Style’
Select End
Find ‘\m’, ‘E’
Select End
The trouble is, the macro works fine sometimes and other times will not remove the attributes. Any ideas about the better way to do the macro? I want to keep the typeface and font size and just remove things like italics, bold, underline, superscript, etc. (the "options" under Character palette).

Thanks in advance!
Josh
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Removing (some) character attributes . . .

Post by martin »

Hi Josh- I'm a bit confused by this line:

Code: Select all

Menu ‘:Format:Character Style:Character Style’
Do you really have a character style called "Character Style"? Is that some kind of base/plain style you've configured?
goldste4
Posts: 98
Joined: 2010-02-22 15:06:48

Re: Removing (some) character attributes . . .

Post by goldste4 »

Hi Martin,

Thanks for the help. I don't have character style defined; when I made the macro (and new to NWP, which I still am!) I assumed that it was some sort of default (or neutral) definition that was applied to all characters. When I tried applying it to text with italics, bold, etc., it seemed to work (and does work about 50–80% of the time) to 'reset' the text, so that the italics, bold, etc, is gone, and so I build the macro around it. However, it also doesn't work consistently, and I haven't been able to figure out exactly why . . .

Thanks,
Josh
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Removing (some) character attributes . . .

Post by martin »

Hrm, well you must have added such a character style at some point. When I run your macro I am warned by NWP:
Unknown menu item path:
:Format:Character Style:Character Style
Which is as I expect, since I have no such character style in my document.

But onward to the problem you're trying to solve! All your macro does is change the character style, which is just one part of the attributes NWP considers. Generally speaking, NWP gathers attributes like so:

1. Paragraph Style (eg: Heading 4)
2. Character Style (eg: Emphatic)
3. Manually applied attributes (eg: those applied using the Character palette)

Attributes found later in the list override those found earlier, eg: the "Unitalic" attribute found in the Heading 4 paragraph style is overridden by the "Italic" attribute found in the Emphatic character style. Your macro merely changes the character style, which still lets either the paragraph style or manually applied attributes add bold/etc to your text.

So, what to do? You'll want to add a manual "Unbold" attribute, so that it has the final word in the matter. You do that by toggling the bold menu, but only if it is check marked, eg:

Code: Select all

If Menu State ':Format:Bold'
	Menu ':Format:Bold'
End
Now, you said you wanted to turn off all the character options. Some of those you'll want to toggle off like bold if necessary, but others are simpler because the menus provide direct "None" states. Here's the full macro:

Code: Select all

Menu ':Edit:Select:Select Word'

If Menu State ':Format:Bold'
	Menu ':Format:Bold'
End
If Menu State ':Format:Italic'
	Menu ':Format:Italic'
End
If Menu State ':Format:Shadow'
	Menu ':Format:Shadow'
End
Menu ':Format:Baseline:No Super/Sub'
Menu ':Format:Underline:None'
Menu ':Format:Strikethrough:None'
Menu ':Format:Text Color:Black'
Menu ':Format:Character Case:No Case Change'

Select End
Find ‘\m’, ‘E’
Select End
goldste4
Posts: 98
Joined: 2010-02-22 15:06:48

Re: Removing (some) character attributes . . .

Post by goldste4 »

Hi Martin,

The 'character style' must have been an artifact of importing my Wordperfect documents that then got into my NisusNewFile when I was first getting NWP all set up—and I've always just assumed that it was a Nisus default style! I looked at the style, it has no content: it's based on 'none' and has no attributes at all (which may have been the key to its semi-success, I suppose).

Thanks very much for excellent help as usual. The macro works perfectly, but with one problem — once I've run the macro on a word, my usual macro (below) to make a word italic no longer changes that word's character attribute (the word remains without italics). However my Make Word Italic macro works as expected on words where I haven't run your new macro. Similarly, when I manually select a word that I've used your macro on and then press Cmd-i, that word does become italic.

Code: Select all

Menu ‘:Edit:Select:Select Word’
Menu ‘:Format:Character Style:Emphatic’
Select End
Find ‘\m’, ‘E’
Select End
Any suggestions?
Thanks again,
Josh
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Removing (some) character attributes . . .

Post by martin »

goldste4 wrote:Thanks very much for excellent help as usual. The macro works perfectly, but with one problem — once I've run the macro on a word, my usual macro (below) to make a word italic no longer changes that word's character attribute (the word remains without italics).
Happy to help! So it all comes back to that 1 to 3 list of attribute considerations. Character styles come at #2, which means that manually applied attributes can override them. That's why your Emphatic character style doesn't do anything; the macro had applied a manual "Unitalic" attribute.

From what you've told me, it seems like you consistently work with character styles. So instead of having that first macro force "unitalic", let's remove all manually applied attribute that could disrupt the functioning of your plain "Character Style" style. The first macro then becomes:

Code: Select all

Menu ‘:Edit:Select:Select Word’
Menu ‘:Format:Remove Attributes Except Styles’
Menu ‘:Format:Character Style:Character Style’
Select End
Find ‘\m’, ‘E’
Select End
That will leave your text with no manually applied attributes, so your Emphatic style can do its work. The only scenario where the macro will leave bold/etc intact now is if your paragraph style enforces that formatting, which is likely not an issue.
goldste4
Posts: 98
Joined: 2010-02-22 15:06:48

Re: Removing (some) character attributes . . .

Post by goldste4 »

Hi Martin, perfect! That solves (and explains) the problem. Thanks again, Josh
Post Reply