macro: preserve some character attributes, but add italics

Get help using and writing Nisus Writer Pro macros.
Post Reply
NisusUser
Posts: 257
Joined: 2011-01-12 05:32:38

macro: preserve some character attributes, but add italics

Post by NisusUser » 2012-11-28 06:35:40

I want to change [this] to this, or [this] to this, or [this] to this, i.e. text with brackets to italicized text. However, sometimes the target text in brackets already has bold, underline or such applied. All I want is to add italics. I'm using the PowerFind Pro find and replace formula in the attached screenshot. However, if the text has other attributes applied, it removed them and adds back italics only. How can I get want I need? Do I need to do separate find/replace functions for differing text, i.e. one for text already in bold, one for text already in bold & underline, one for text that has no attributes applied yet, etc.?
Attachments
imprecise find-replace_deletes formatting.png
imprecise find-replace_deletes formatting.png (28.09 KiB) Viewed 4038 times

User avatar
phspaelti
Posts: 912
Joined: 2007-02-07 00:58:12
Location: Japan

Re: macro: preserve some character attributes, but add itali

Post by phspaelti » 2012-11-28 07:32:21

I would use a macro for this. Then rather than do Find and Replace, I would do this:

Code: Select all

Find All ...
Italic
So I'd just use the Find capability to Find things and then apply the formatting "by hand" (so to speak).
Hope this helps.
philip

NisusUser
Posts: 257
Joined: 2011-01-12 05:32:38

Re: macro: preserve some character attributes, but add itali

Post by NisusUser » 2012-11-28 20:44:21

Philip,

I guess I don't know fully the difference between Find and Replace and a macro. I was just assuming a macro was a Find and Replace expression that was saved and run as a macro. Maybe you can help me out as to what you meant.

Attached is a macro I made to do this. For some reason it doesn't work, though. I thought I followed your examples. Would you be willing to help me out?

Thanks!
Attachments
EC-brackets to italics.nwm
(823 Bytes) Downloaded 226 times

User avatar
phspaelti
Posts: 912
Joined: 2007-02-07 00:58:12
Location: Japan

Re: macro: preserve some character attributes, but add itali

Post by phspaelti » 2012-11-29 05:07:28

Hi I have fixed your macro.(Keeping my fingers crossed.) If you do it right then you don't need three Find/Replace statements. Your last one will suffice.
EC-brackets_to_italics_(simple).nwm
(3.09 KiB) Downloaded 248 times
What does "do it right mean"? Well the attribute sensitive find/replace pays attention to the attributes. All the attributes. So once you paste the statement into a file it takes on other attributes (paragraph style, for example), and then it stops working. The solution for such cases is to use the "Remove Attributes and Styles" command, and then add back just the attributes you want.

to be continued…
Last edited by phspaelti on 2012-11-29 05:13:39, edited 1 time in total.
philip

User avatar
phspaelti
Posts: 912
Joined: 2007-02-07 00:58:12
Location: Japan

Re: macro: preserve some character attributes, but add itali

Post by phspaelti » 2012-11-29 05:12:22

Anyhow I hate fussing with the attributes so I suggested a second method.
EC-brackets_to_italics_(2_step).nwm
(3.14 KiB) Downloaded 222 times
As I described above, you can use Find/Replace to select things, and then apply the styles you want. As long as the Find part doesn't care about styles, this works, a bit more "reliably".

A macro can contain more than just a list of Find/Replace statements. You can add any menu commands (just type them exactly as the menu name says), and then there is a whole macro language if you want to get really elaborate.

Anyhow good luck with your macro writing. :wink:
philip

NisusUser
Posts: 257
Joined: 2011-01-12 05:32:38

Re: macro: preserve some character attributes, but add itali

Post by NisusUser » 2012-11-29 07:04:45

Thank you very much for all your help and tutoring!

Post Reply