How does the macro recorder work?

Useful stuff for users and developers of the XML based dynamic publishing system "Arbortext". All information in this wiki came from posts to the Arbortext Adepters mailing list that were identified by members of that list as being extremely useful because the mailing list has moved around over the years. For more information see the group FAQ.

This forum and its sub-forums are open to the public.
Forum rules
Discussion posts to this group should be relevant to Arbortext users. Posts on other products or from vendors are welcome, so long as the post also mentions or includes Arbortext in the subject matter. General posts on dynamic publishing and posts from vendors other than PTC will be subject to higher scrutiny and should generally avoid posting here (especially if the referenced material does not mention Arbortext). Advertisement posts for other products (e.g., "check out my product as an alternative") are not welcome. This forum is for Arbortext users to communicate with other Arbortext users about working with Arbortext products.

All posts to this forum are moderated.

User avatar
liz
Posts: 266
Joined: Sun May 31, 2015 2:34 am

How does the macro recorder work?

Postby liz » Mon Jun 15, 2015 5:28 pm

Answered by: Brandon Ibach and Dugald Topshee
Last Updated: 2008-08-12
Editors note by Liz Fraley: PTC/User links updated to communities.ptc.com after mailing list moved in 2015


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:

Code: Select all

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

https://www.ptcusercommunity.com/message/321467#321467

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:

Code: Select all

<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


You do not have the required permissions to view the files attached to this post.

Return to “Arbortext Code Archive (adepters.org) (Public)”

Who is online

Users browsing this forum: Yahoo [Bot] and 11 guests