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

Multiple Para Styles

Community Beginner ,
Oct 19, 2022 Oct 19, 2022

Copy link to clipboard

Copied

Hello. I have the following script that verifies and corrects uppercase acronyms on headings—but is limited to a single paragraph style. It would be a significant improvement to make it work on multiple paragraph styles. Also, this function requires the word acronym for every entry; perhaps there is a way to clean up the list. Thank you guys.

 

app.findChangeTextOptions.caseSensitive = false;

app.findChangeTextOptions.wholeWord = true;

 

acronym ('ABC');

acronym ('BBC');

acronym ('CBS');

acronym ('FCC');

 

function acronym (myFind) {

   app.findTextPreferences.findWhat = myFind;

   app.findTextPreferences.appliedParagraphStyle = "Heading1";

   app.changeTextPreferences.capitalization = Capitalization.ALL_CAPS;

   app.activeDocument.changeText();

TOPICS
Scripting

Views

168

Translate

Translate

Report

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 , Oct 19, 2022 Oct 19, 2022

Hi @joaquinm13464128, see how you go with this:

var acronyms = [
    'ABC',
    'BBC',
    'CBS',
    'FCC'
];

var styleNames = [
    'Heading1',
    'Heading2',
    'Heading3',
    'Heading4'
];


function main() {

// string all the acronyms together for the grep
var findWhat = '(?i)\\b(' + acronyms.join('|') + ')\\b';

// gather all the paragraphs in these styles
var found = findTextInParagraphStyles(app.activeDocument, findWhat, styleNames);

// change them all to CAPS
for (var i = 0; i < f
...

Votes

Translate

Translate
Community Expert ,
Oct 19, 2022 Oct 19, 2022

Copy link to clipboard

Copied

Hi @joaquinm13464128, see how you go with this:

var acronyms = [
    'ABC',
    'BBC',
    'CBS',
    'FCC'
];

var styleNames = [
    'Heading1',
    'Heading2',
    'Heading3',
    'Heading4'
];


function main() {

// string all the acronyms together for the grep
var findWhat = '(?i)\\b(' + acronyms.join('|') + ')\\b';

// gather all the paragraphs in these styles
var found = findTextInParagraphStyles(app.activeDocument, findWhat, styleNames);

// change them all to CAPS
for (var i = 0; i < found.length; i++)
    found[i].contents = found[i].contents.toUpperCase();


};

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Capitalize Acronyms');


/**
 * Find text set in all multiple
 * paragraph styles.
 * @author m1b
 * @version 2022-10-19
 * @param {Document|Page|Story} findWhere - any Indesign Object with a findGrep method.
 * @param {String} findWhat - the grep string.
 * @param {Array<String>} styleNames - the paragraph style names to find.
 * @returns {Array<Paragraph>}
 */
function findTextInParagraphStyles(findWhere, findWhat, styleNames) {

    if (styleNames.constructor.name == 'String')
        styleNames = [styleNames];

    if (!findWhere.hasOwnProperty('findGrep'))
        throw Error('findTextInParagraphStyles cannot find in "' + findWhere + '".');

    // reset grep prefs
    app.findGrepPreferences = NothingEnum.NOTHING;
    app.changeGrepPreferences = NothingEnum.NOTHING;

    var found = [];

    // find criterion
    app.findGrepPreferences.findWhat = findWhat;

    for (var i = 0; i < styleNames.length; i++) {

        try {

            // find criterion
            app.findGrepPreferences.appliedParagraphStyle = styleNames[i];

            // do the find
            found = found.concat(findWhere.findGrep());

        } catch (error) {
            /* paragraph style not found */
        }

    }

    return found;

};

- Mark

Votes

Translate

Translate

Report

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 ,
Oct 19, 2022 Oct 19, 2022

Copy link to clipboard

Copied

If the font used in the paragraph styles has AllCaps, then it's easier to change the styles. Often that's a better solution because the underlying text is still upper/lower case, which may still be required in index markers, running headers, etc.

Votes

Translate

Translate

Report

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 ,
Oct 19, 2022 Oct 19, 2022

Copy link to clipboard

Copied

Thanks Peter. It's funny, because I deliberately changed it to a hard change because it bothered me that any future resetting or changing of the style would revert it to the wrong case. Definitely would come down to specifics of the job I guess.

Votes

Translate

Translate

Report

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 ,
Oct 19, 2022 Oct 19, 2022

Copy link to clipboard

Copied

Definitely would come down to specifics of the job I guess.

Absolutely.

Votes

Translate

Translate

Report

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 Beginner ,
Oct 19, 2022 Oct 19, 2022

Copy link to clipboard

Copied

LATEST

Hi Mark,

It works very well! This is a true piece of art now. Now it's going to be much easier to populate the list and work with multiple para styles. Thanks again for the quick response and your effort.

Best,

Joaquin

Votes

Translate

Translate

Report

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