Home Forums General XMetaL Discussion Track changes default on Reply To: Track changes default on

Derek Read

Reply to: Track changes default on

Try something like this:

[code]var rng = ActiveDocument.Range;
var docStr = rng.TextWithRM;
var has_change_mark = false;
if(docStr.search(/ -1) {
has_change_mark = true;
if(docStr.search(/ -1) {
has_change_mark = true;
if(has_change_mark) {
ActiveDocument.TrackRevisions = true;
//else: do nothing

Note: The code above may look odd, and it is a bit unusual. Normally there are far better ways to find content (including PIs) in a document. The APIs getNodesByXPath() and GotoNext() work for PIs and would be preferable, but specifically do [u]not[/u] find Revision Marking PIs. The nature of the Revision Marking PIs makes that impossible as they exist outside of the main content of the DOM in XMetaL (for good reasons I won't try to explain). This script grabs the document's content as a string using the special TextWithRM property (to bring in the revision marks), then examines that text using JScript regular expressions (normally something that would be pretty dumb to do on an XML string but that is “good enough” for this case, and has the added benefit of being fast). There is a special PI for moving between revision marks named GotoNextChange(), but that results in a dialog being displayed when no revision marks are found and obviously you want this script to run silently.