cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

Writing a "replace all" macro

cmakler
1-Newbie

Writing a "replace all" macro

Greetings all,

I'm trying to write a "replace all" macro that searches for a list of about 60 words and replaces them with an element containing that word. For example, I would like to replace all instances of the word "Arbortext" with the following:

<expression expression="Arbortext">~Arbortext~</expression>

(Don't ask!)

The other restriction: the change needs to be tracked.

I've run into a few problems. The first is that if you just use a macro to record a "replace all" operation, it doesn't record the fact that you asked it to replace all instances; rather, it just records what it actually replaces. So if you record a replace all when the document contained two instances of the word "Arbortext," and then run that macro on a document that contains three instances, only the first two get changed.

The second problem is that the find/replace doesn't seem to be able to insert an element. I've encountered this in the past, too, and it's been annoying! I feel there must be some way to insert markup using find/replace...


A third, more technical problem is that I haven't been able to find a syntax for the macro language that Arbortext uses -- or even just a reference as to what that language is so that I could look up the syntax!

Any help with any or all of these issues would be greatly appreciated! Thanks!

Chris

6 REPLIES 6
bibach
1-Newbie
(To:cmakler)

Chris,

See the topics under "Authoring", "Macro recorder" for details about how
the recorder is used and where the macros are stored.

The macro recorder stores your actions as a series of statements in the
Arbortext Command Language (ACL), which is the built-in scripting
language in which many of the built-in features of the editor are
implemented. ACL is not a difficult language to learn. The
documentation, primarily in the help file under "Arbortext Command
Language (ACL)", is quite good.

Given that the macro recorder will help you get started by recording a
reasonable series of ACL statements to do approximately what you want,
it should not be too hard to tweak the results. You can open the MCF
file in which the macro is stored in Arbortext Editor itself, as it is
an XML file. It shouldn't be too hard to see which ACL command is
executing the search, then look the command up in the help file index
for details about how you can modify it to do what you want.

Give it a shot and come on back with any specific ACL questions, if you
get stuck.

Brandon Ibach
Lockheed Martin Space Systems
Cape Canaveral, FL
321-476-7051

Thanks Brandon!

That's more or less the process I was using - I'd found the macro file. I just mostly needed to see where more documentation was. I'll let you know if I run into any more roadblocks.

Chris
dugald
1-Newbie
(To:cmakler)

Just to help you along, this one line of ACL will make the global
change that you're looking for:
s -a -m '~Arbortext~'<expression <br="/>expression="Arbortext">~Arbortext~</expression>'

That's just the substitute command with the -m (markup) and -a (all)
parameters and the find and replace values delimited with single
quotes so that you can use the double quotes for the attribute in your
replacement string. If the macro recorder uses ACL, then there should
be some variant of this command in the script it recorded.

Also for your second problem, you can insert markup with the
Find/Replace dialogue box (at least in version 5.1 I didn't test it in
any other version, but I'm sure they're the same). Just make sure the
"Match Markup" button is checked off and add the new element (opening
and closing tag) to the Replace with box around the string you want to
use.

Cheers,

Dugald

Quoting "Makler, Chris (Aplia)" <->:

> Thanks Brandon!
>
> That's more or less the process I was using - I'd found the macro
> file. I just mostly needed to see where more documentation was. I'll
> let you know if I run into any more roadblocks.
>
> Chris
>

Dugald, this worked great.

Recording the script didn't work, by the way, as the command line window goes dark when the macro is recording...but it was easy enough to edit the .mcf file.

For anyone who might find this useful, I've attached an Excel spreadsheet where you can enter a number of items to search/replace. This generates the code for the macro in column C, which you can cute and paste into an .mcf file.

The code looks like this:

<macros>
<macro name="FindReplace">
<desc>This macro replaces a number of objects from a list. Exported from Excel on 8/12</desc>
<script type="application/x-acl" xml:space="preserve">
s -a -m 'sad'happy'
s -a -m 'needs to be bold'needs to be bold'

message "Done.";]]></script>
</macro>
</macros>

Thanks again for all your help!

Chris

OK, I'm in trouble again.

Is there an adjustment to the s -a -m syntax so that it doesn't search within some elements? Because when I run this more than once it finds the ~Arbortext~ within the <expression> tag and does it all over again - and since <expression> tags can't accept <expression> tags, I get lots of nice beeps.
dugald
1-Newbie
(To:cmakler)

Hi Chris,

With regards to your first question, I'm afraid there's no "except inside" flag on the
substitute command so you can't write a one-line command that will "replace all 'x' with
'y' except when 'x' is inside ". The good news is that you can accomplish this fairly
easily by writing a custom ACL function tha...

































































[Hide Quoted Text] OK, I'm in trouble again.

Is there an adjustment to the s -a -m syntax so that it doesn't search within some
elements? Because when I run this more than once it finds the ~Arbortext~ within the
<expression> tag and does it all over again - and since <expression> tags can't accept
<expression> tags, I get lots of nice beeps.

So: I'd like it do this exact thing, but to exclude <expression> tags. Any pointers?

One other question: Once it does this, I want it to insert some code at the top of the
file. Specifically, before the script runs, the top of the file looks like this

...
<lexicons>
<lexicon name="internationalConversions">
<term>
<term-model>mile</term-model>
<term-value>kilometer</term-value>
</term>
</lexicon>
<lexicons>
...

I would like to write a line of code that inserts

<term>
<term-model>yard</term-model>
<term-value>meter</term-model>
<term>

within the <lexicon> tag, as part of this macro. This must be amazingly easy to do, but
again, I can't figure out where to look for this. The closest I've found is insert_tag
but that doesn't tell me how to tell it to look for the first instance of the element
<lexicon> and insert it under there. I tried doing a find-replace (using the very
helpful method outlined before), replacing

<lexicon name="internationalConversions">

With

<lexicon name="internationalConversions">
<term>
<term-model>yard</term-model>
<term-value>meter</term-model>
<term>

But it told me I was unbalanced, which is undoubtedly true.

Any help? I know this must be a hopelessly newbie question...

Chris
Announcements