How does the macro recorder work?

From AdeptersWiki

Jump to: navigation, search

Answered by: Brandon Ibach and Dugald Topshee
Last Updated: 2008-08-12


Contents

Question by Chris Makler

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!


Answer by Brandon Ibach

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.


Dugald Topshee added

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 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.

http://portal.ptcuser.org/p/fo/st/post=65806&anc=p65806#p65806

Reply by Chris Makler

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"><![CDATA[

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

See also

Personal tools