Skip to main content
Inspiring
October 19, 2023
Answered

Find/replace font size with decimal value

  • October 19, 2023
  • 4 replies
  • 1137 views

Hi all,

I have to replace all 15,7 points texts to 15 points. Find/Change dialog does let me enter a decimal value, but somehow I could not get it to find a decimal value. I also tried the script below, but no luck 😞

var doc = app.activeDocument;

app.findGrepPreferences=app.changeGrepPreferences=null;
app.findGrepPreferences.pointSize = "15,7pt";
app.changeGrepPreferences.pointSize = "15pt"
doc.changeGrep();

Does anyone know a workaround?

Thanks,
Rogerio

Correct answer m1b

@TᴀW has perfectly pinpointed the issue.

 

My contribution is the following script, that takes the guesswork out by requiring the user—Hi @Rogerio5C09!—to select a bit of text first. That way we can just pass the actual pointSize to the findGrep.

- Mark

 

/**
 * Set PointSize With ChangeGrep.js
 * Will find any text in the document with
 * pointSize matching the selected text's
 * pointSize and set it to a chosen value.
 * @author m1b
 * @discussion https://community.adobe.com/t5/indesign-discussions/is-there-a-way-to-remove-all-the-unused-data-placeholders/m-p/14172138
 */
function main() {

    var doc = app.activeDocument;

    setPointSize(doc, doc.selection[0], undefined);

};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Set Point Size');


/**
 * Sets the pointSize of any text found in `target` object
 * that matches pointSize of `sourceText`.
 * Used in case where it is difficult to manually target
 * a particular pointSize due to obscured unit conversion.
 * @author m1b
 * @date 2023-10-20
 * @param {Application|Document|Story|Text} target - the changeGrep target object.
 * @param {Text} sourceText - the text with pointSize to find.
 * @param {String|Number} [newPointSize] - the pointSize to set (default: ask user).
 */
function setPointSize(target, sourceText, newPointSize) {

    if (
        target == undefined
        || target.changeGrep == undefined
    )
        throw Error('setPointSize: bad `target` parameter.');

    if (
        sourceText == undefined
        || !sourceText.hasOwnProperty('pointSize')
    )
        throw Error('setPointSize: bad `sourceText` parameter.');

    newPointSize = newPointSize
        || prompt('Change to pointSize', sourceText.pointSize);

    if (newPointSize == undefined)
        return;

    app.findGrepPreferences = NothingEnum.NOTHING;
    app.changeGrepPreferences = NothingEnum.NOTHING;

    // get the point size from the selected text
    app.findGrepPreferences.pointSize = sourceText.pointSize;
    app.changeGrepPreferences.pointSize = newPointSize

    target.changeGrep();

};

4 replies

Community Expert
October 20, 2023

Or get all point sizes and change those that are greater than 15.70 and smaller than 15.71 (or whatever range).

TᴀW
Brainiac
October 19, 2023

It's perhaps not so strange.

If somebody applied a value of, say, "3mm" to some text, InDesign will convert that to a pt value, and will display 8.504.

However, searching for font with the size 8.504 won't work, because really, the text size is 8.50393700787402.

But even searching for 8.50393700787402 won't work!

The only thing that seems to work is to type 3mm in the Find What point size field. This is immediately be turned into 8.504, but it will actually find the relevant text.

So.... perhaps your best bet is to try and figure out what the original unit was, and type the find-what size in those original units?

m1b
m1bCorrect answer
Community Expert
October 19, 2023

@TᴀW has perfectly pinpointed the issue.

 

My contribution is the following script, that takes the guesswork out by requiring the user—Hi @Rogerio5C09!—to select a bit of text first. That way we can just pass the actual pointSize to the findGrep.

- Mark

 

/**
 * Set PointSize With ChangeGrep.js
 * Will find any text in the document with
 * pointSize matching the selected text's
 * pointSize and set it to a chosen value.
 * @author m1b
 * @discussion https://community.adobe.com/t5/indesign-discussions/is-there-a-way-to-remove-all-the-unused-data-placeholders/m-p/14172138
 */
function main() {

    var doc = app.activeDocument;

    setPointSize(doc, doc.selection[0], undefined);

};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Set Point Size');


/**
 * Sets the pointSize of any text found in `target` object
 * that matches pointSize of `sourceText`.
 * Used in case where it is difficult to manually target
 * a particular pointSize due to obscured unit conversion.
 * @author m1b
 * @date 2023-10-20
 * @param {Application|Document|Story|Text} target - the changeGrep target object.
 * @param {Text} sourceText - the text with pointSize to find.
 * @param {String|Number} [newPointSize] - the pointSize to set (default: ask user).
 */
function setPointSize(target, sourceText, newPointSize) {

    if (
        target == undefined
        || target.changeGrep == undefined
    )
        throw Error('setPointSize: bad `target` parameter.');

    if (
        sourceText == undefined
        || !sourceText.hasOwnProperty('pointSize')
    )
        throw Error('setPointSize: bad `sourceText` parameter.');

    newPointSize = newPointSize
        || prompt('Change to pointSize', sourceText.pointSize);

    if (newPointSize == undefined)
        return;

    app.findGrepPreferences = NothingEnum.NOTHING;
    app.changeGrepPreferences = NothingEnum.NOTHING;

    // get the point size from the selected text
    app.findGrepPreferences.pointSize = sourceText.pointSize;
    app.changeGrepPreferences.pointSize = newPointSize

    target.changeGrep();

};
New Participant
August 7, 2025

this was excellent thanks a ton

New Participant
October 19, 2023

It should be posibble, i tested it in the latest version of indesign. 

 

Make sure you have nothing in the "Search for (zoeken naar)" and "change to (wijzigen in)" fields,
otherwise is searches for that input in the styles you entered. 


Tip for next time, work with paragraph styles, then you only had to change that paragraph style.

Inspiring
October 19, 2023

Hi @Tammoh , thanks for getting back to me 🙂

I can enter the decimal value on Find Format, but when I click on "Find Next" it doesn't find anything. Weird, right?

James Gifford—NitroPress
Brainiac
October 19, 2023

The only truly consistent way to accomplish this may be to apply styles to the entire document. Ad-hoc style search and replace is always limited by one factor or another.

m1b
Community Expert
October 19, 2023

Have you tried searching for the number, rather than the string? 

app.findGrepPreferences.pointSize = 15.7;
Inspiring
October 19, 2023

Hey @m1b, I gave it a try, but no luck. It seems that Find/Change doesn't work with decimal values.