Copy link to clipboard
Copied
Hi Everyone,
This is my first time creating a script for FM and I'm having some trouble getting this to work. I have some index markers that have had a semicolon replaced with a colon, which is creating havoc in my Index file. I wanted to use an regex expression with a Find and Replace script to correct them. There are a great many of these to find and fix and doing it manually isn't too appealing (though if I have to, I will). My script, which has been stolen/cobbled from other posts here, seems to run (I get the message box showing X number of replacements made) but it doesn't actually perform the replace part (script below). I'm not sure it's performing the Find part either, come to think of it. Any help would be most appreciated!
Thank you in advance,
Megan
1 Correct answer
A couple of things: your regexR should be a string, not a regular expressions object:
regexR = ";$1";
Then inside the regex.test, you need this:
marker.MarkerText = marker.MarkerText.replace (regex, regexR);
Copy link to clipboard
Copied
A couple of things: your regexR should be a string, not a regular expressions object:
regexR = ";$1";
Then inside the regex.test, you need this:
marker.MarkerText = marker.MarkerText.replace (regex, regexR);
Copy link to clipboard
Copied
Thank you very much! You've literally saved me days of insanely boring manual work!
Copy link to clipboard
Copied
One of the things I do when developing scripts is to work with a single selected item in the document. For example, you can use this code to get the currently selected marker in the active document. The benefit is that you can make sure that your basic code works on the selected marker before expanding it to work on all markers in the document (or book).
var doc, textRange, textItems, marker;
// Set a variable for the active document.
doc = app.ActiveDoc;
// Set a variable for the selected text range in the document.
textRange = doc.TextSelection;
// Get a list of markers in the selected text.
textItems = doc.GetTextForRange(textRange,Constants.FTI_MarkerAnchor);
// Make sure there is a marker in the selection.
if (textItems.len) {
// Get the first marker and display its marker text and marker type.
marker = textItems[0].obj;
alert (marker.MarkerText);
alert (marker.MarkerTypeId.Name);
}
Copy link to clipboard
Copied
This is wonderful! Thank you very much for this, I've saved it to my HD for future use. I'm awesome working with VBA scripts but very new to these FM scripts. I'm still learning the syntax and how to debug and I really appreciate the help 🙂

