how to separate tasks?

Get help using and writing Nisus Writer Pro macros.
Post Reply
Pat
Posts: 28
Joined: 2009-09-04 13:11:25

how to separate tasks?

Post by Pat »

Hi,
I am making a macro consisting of a very long list of "Find and replace". Everything was working fine but now color attributes get sometimes applied to the preceding task. What should I do to prevent this? Is there a command to separate tasks?
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: how to separate tasks?

Post by martin »

Hi Pat- I'm not sure I understand exactly what you're saying. Do you mean that parts of the text/code in your macro file have improperly changed color somehow? Macro files are like any other document, meaning you can have different fonts/colors/attributes applied to different pieces of the document.
Pat
Posts: 28
Joined: 2009-09-04 13:11:25

Re: how to separate tasks?

Post by Pat »

I fixed the problem I had this morning (I don't know why it works now but it works). The macro is so long that it is not surprising that this kind of problem arises since I did not know anything about macros just a few weeks ago. My macro is composed of dozens of simple components. I was wondering: do you think it would be easier to transform those components in smaller macros and then create a list of those components in an other macro? Thank you for your help.
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: how to separate tasks?

Post by martin »

You could take that approach, of splitting up your macro into multiple macros, and then calling those smaller macros from some master macro. I think that only makes sense if the smaller sub-tasks are meaningful on their own, but it's really a matter of personal taste and organization. Do whatever works best for your brain!
Pat
Posts: 28
Joined: 2009-09-04 13:11:25

Re: how to separate tasks?

Post by Pat »

Hi again,

I think I know now why sometime things go wrong but I don't know how to fix it. I have a master macro who runs dozens of macros in a certain order. Individually, the small macros are working fine. However, when I get the master macro running, if one of the small macros doesn't find in the text the string of characters it is supposed to modify, it modifies the string of the previous macro. Is there a way I can prevent this to happen?

Thank you
Groucho
Posts: 497
Joined: 2007-03-03 09:55:06
Location: Europe

Re: how to separate tasks?

Post by Groucho »

Hi, Pat.

Have you set Find and Replace to operate in selection and to keep selection (something like Find and Replace “abc”, “def”, “sS”)? If so, a macro line is bound to process whatever was left selected in the previous line(s).

It would be interesting to see the macro itself. Even a few lines would be of help.

Cheers, Henry.
Pat
Posts: 28
Joined: 2009-09-04 13:11:25

Re: how to separate tasks?

Post by Pat »

Hi Henry

Here is an example,

Find all 'a', 'Eam'
$color = Color.newWithHexTriplet 'FFCC00'
Set Text Color $color

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

Re: how to separate tasks?

Post by phspaelti »

Hi Pat,

you can prevent the problem if you make the code conditional on the actual finding of the text. You can modify your code like this:

Code: Select all

If Find all 'a', 'Eam'
$color = Color.newWithHexTriplet 'FFCC00'
Set Text Color $color
end
Note that I put an "if" on the line with the find, and and "end" after the other instructions. Now the lines in between will only execute if the find instruction actually finds something.

hope this helps
philip
philip
Groucho
Posts: 497
Joined: 2007-03-03 09:55:06
Location: Europe

Re: how to separate tasks?

Post by Groucho »

Ah, I see now.

This is a common mistake. Performing a macro is like executing a series of commands in a row. When you operate a search, either via a macro or the Find/Replace window, the program leaves all found/replaced text selected.

Now, suppose all your b's in a document are selected as a result of a previous Find and Replace command, and you go on searching all of the f's because you want apply them the color red. Suppose, also, that there are no f's in your document. Then the macro will go on to the next step, and will apply a color red to whatever is selected. That's why you'll end up with all your b's, not f's, colored red – because the Find and Replace command didn't change the selections.

Here you have two ways.

1. An if pattern, as explained by Philip.
2. A Find and Replace command of this kind:

Code: Select all

Find and Replace "re", "\\0", "aEmU"
(Where re is a regular expression.)

Once you have written this line, select it and remove all attributes via Format > Remove Attributes and Style. Then select \0 and go to Format > Text Color > Show Text Colors and pick a color from the system color picker.

I hope this helps.

Cheers, Henry.
Pat
Posts: 28
Joined: 2009-09-04 13:11:25

Re: how to separate tasks?

Post by Pat »

Thank you very much.

Pat
Post Reply