Query 2:
Main();
function Main() {
var doc = app.activeDocument,
parStyles = doc.paragraphStyles,
swatch_1 = doc.swatches.item(“C=60 M=40 Y=0 K=0”),
swatch_2 = doc.swatches.item(“C=15 M=100 Y=100 K=0”),
i, parStyle;
if (swatch_1.isValid && swatch_2.isValid) {
for (i = 0; i < parStyles.length; i++) {
parStyle = parStyles[i];
if (parStyle.fillColor == swatch_1) parStyle.fillColor = swatch_2;
}
}
else {
alert(“A swatch doesn't exist.”);
}
}
//———————————————–
Query 1:
I still don't understand what you want to achieve. Scripting grep style is quite straightforward — as in the user interface, you have to set only two parameters: appliedCharacterStyle (the character style applied to the text) and grepExpression (the GREP expression used to apply automatic styling).
Probably, for the first parameter, you might want to use ^\d+ to apply the character style to any number of digits at the beginning of a line. I don't get what you mean by (Figure No : *) — a number followed by colon and some text?
First you have to create and test a grep-expression in InDesign to make sure that it works as expected. Then you can copy and paste it to the script and escape backslashes (double them in script).
Second parameter — character style:
grepStyle.appliedCharacterStyle = doc.characterStyles.item(“Type in your character style here”);
I used the following line in my example just to be on a safe side: if the character style doesn't exist in the document, create it, name it as “Figure numbers” and apply Bold to it. You can remove it if you're sure that the style is always present in the document, otherwise the script would throw an error.
if (!charStyle.isValid) doc.characterStyles.add({name:”Figure numbers”, fontStyle:”Bold”});