Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Apply an object style to blocks containing a certain paragraph style

Explorer ,
Nov 07, 2025 Nov 07, 2025

Hi ! I would like to search for blocks containing a certain paragraph style and apply an object style to those blocks, do you know if it's possible ? Thank you for you help ! 

TOPICS
Experiment , Print , Scripting
243
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 07, 2025 Nov 07, 2025

Hi @99drine Here's a simple script that does what you ask. You just need to edit the name of the paragraph style and object style in the script before running.

- Mark

/**
 * @file Set Object Style Of Found Text Frames.js
 *
 * Example showing searching for a paragraph style
 * and then applying an object style to the found
 * text's frame(s).
 *
 * @author m1b
 * @version 2025-11-08
 * @discussion https://community.adobe.com/t5/indesign-discussions/apply-an-object-style-to-blocks-containing-a-ce
...
Translate
Community Expert ,
Nov 07, 2025 Nov 07, 2025

You can search for blocks of text in a certain paragraph style, but you can't apply an object style to that block. Object styles can be applied to frames only. So you'd have to take out those blocks one by one and apply the object style to each of them.

 

What are you trying to achieve?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 07, 2025 Nov 07, 2025

Thank you! I would like to automate the automatic sizing of blocks containing a certain paragraph style to automatically fix a recurring problem of excess text in blocks where this style is applied…

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 07, 2025 Nov 07, 2025

You're after a type fitter. You can't use an object style for that, you'll have to apply point size and/or leading and/or whatever else can reasonably reduce the space that some block of text takes.

 

Take a look at https://typefitter.com/, it's a popular plug-in for fitting type.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 07, 2025 Nov 07, 2025

Thank you! These are captions for drawings. I don't want to change the text, I “just” want to enlarge the blocks so that there is no excess text... I was told that this might be possible with a script?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 07, 2025 Nov 07, 2025

Les options de bloc de texte permettent un dimensionnement automatique du bloc :

Capture d’écran 2025-11-07 à 13.42.33.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 07, 2025 Nov 07, 2025

Oui, merci, j'ai créé un style d'objet avec cette option, et c'est précisément ce que je voudrais réussir à faire : appliquer automatiquement ce style d'objet aux blocs qui contiennent un certain style de paragraphe. (Tous les blocs sont déjà créés, c'est une maquette que je reprends pour une actualisation, je voudrais pouvoir les modifier a posteriori…)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 07, 2025 Nov 07, 2025

Hi @99drine Here's a simple script that does what you ask. You just need to edit the name of the paragraph style and object style in the script before running.

- Mark

/**
 * @file Set Object Style Of Found Text Frames.js
 *
 * Example showing searching for a paragraph style
 * and then applying an object style to the found
 * text's frame(s).
 *
 * @author m1b
 * @version 2025-11-08
 * @discussion https://community.adobe.com/t5/indesign-discussions/apply-an-object-style-to-blocks-containing-a-certain-paragraph-style/m-p/15581289
 */
function main() {

    const TARGET_PARAGRAPH_STYLE_NAME = 'Caption Text';
    const APPLIED_OBJECT_STYLE_NAME = 'Caption Box';

    var doc = app.activeDocument;

    var targetParagraphStyle = getThing(doc.allParagraphStyles, 'name', TARGET_PARAGRAPH_STYLE_NAME);

    if (!targetParagraphStyle)
        return alert('Could not find the paragraph style "' + TARGET_PARAGRAPH_STYLE_NAME + '".');

    var appliedObjectStyle = getThing(doc.allObjectStyles, 'name', APPLIED_OBJECT_STYLE_NAME);

    if (!appliedObjectStyle)
        return alert('Could not find the object style "' + APPLIED_OBJECT_STYLE_NAME + '".');

    // find all text in target paragraph style
    app.findGrepPreferences = NothingEnum.NOTHING;
    app.findGrepPreferences.findWhat = '.*';
    app.findGrepPreferences.appliedParagraphStyle = targetParagraphStyle

    var found = doc.findGrep();

    for (var i = 0; i < found.length; i++) {
        for (var j = 0; j < found[i].parentTextFrames.length; j++) {
            found[i].parentTextFrames[j].appliedObjectStyle = appliedObjectStyle;
            found[i].parentTextFrames[j].clearObjectStyleOverrides();
        }
    }

};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Set caption object style');

/**
 * Returns a thing with matching property.
 * If `key` is undefined, evaluate the object itself.
 * @author m1b
 * @version 2024-04-21
 * @param {Array|Collection} things - the things to look through.
 * @param {String} [key] - the property name (default: undefined).
 * @param {*} value - the value to match.
 * @returns {*?} - the thing, if found.
 */
function getThing(things, key, value) {

    for (var i = 0; i < things.length; i++)
        if ((undefined == key ? things[i] : things[i][key]) == value)
            return things[i];

};
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 08, 2025 Nov 08, 2025

Oh! Wow! It works perfectly! Thank you so much, Mark!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2025 Nov 08, 2025
LATEST

You're welcome!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines