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

Turn on Auto-Size on all text frames that contain a Character Style

Participant ,
Nov 17, 2022 Nov 17, 2022

Copy link to clipboard

Copied

Hi everyone,

Is it possible to create a script to turn on Auto-Size on all text frames that contain text with a specific Character Style applied to them? If so, please set AutoSizing as per below:
frame.textFramePreferences.autoSizingReferencePoint = AutoSizingReferenceEnum.TOP_CENTER_POINT;
frame.textFramePreferences.autoSizingType = AutoSizingTypeEnum.HEIGHT_ONLY;

Thanks in advance,
Rogerio

TOPICS
Scripting

Views

302

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 , Nov 17, 2022 Nov 17, 2022

Hi @Rogerio5C09, how about this?

function main() {

    var doc = app.activeDocument;

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

    // find criteria
    app.findGrepPreferences.appliedCharacterStyle = 'MyCharStyle';

    var found = doc.findGrep();

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

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

            var frame = found[i].parentTextFrame
...

Votes

Translate

Translate
Community Expert ,
Nov 17, 2022 Nov 17, 2022

Copy link to clipboard

Copied

Hi @Rogerio5C09, how about this?

function main() {

    var doc = app.activeDocument;

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

    // find criteria
    app.findGrepPreferences.appliedCharacterStyle = 'MyCharStyle';

    var found = doc.findGrep();

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

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

            var frame = found[i].parentTextFrames[j];

            if (frame.isValid) {
                frame.textFramePreferences.autoSizingReferencePoint = AutoSizingReferenceEnum.TOP_CENTER_POINT;
                frame.textFramePreferences.autoSizingType = AutoSizingTypeEnum.HEIGHT_ONLY;
            }

        }

}; // end main

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Set Autosizing');

 - 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
Participant ,
Nov 18, 2022 Nov 18, 2022

Copy link to clipboard

Copied

LATEST

It worked just as expected! Thank you so much 🙂

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